Unboxed singleton tuples

Simon Marlow marlowsd at gmail.com
Mon Aug 18 04:13:20 EDT 2008


Tim Chevalier wrote:
> On 8/14/08, Roman Leshchinskiy <rl at cse.unsw.edu.au> wrote:
>>  IIUC, the practical difference is this. If you have
>>
>>   f :: Int -> (# Int #)
>>
>>  then
>>
>>   case f m of (# n #) -> bar n
>>
>>  will call f before calling bar but will not evaluate n.
> 
> I fear I'm still not enlightened. I see how your example works, but in
> the particular context where GHC introduces these singleton tuples,
> the tuple will contain an unboxed value (the result of a foreign
> function call.) So if n is unboxed, isn't
> case f m of (# n #) -> bar n
> exactly equivalent to
> bar $! (f m)
> ?

Yes - in the case where the value is unboxed (or unlifted), it makes no 
difference to wrap it in a singleton unboxed tuple.  I actually have no 
idea why we use (# State# RealWorld #) rather than just State# RealWorld in 
that case.  Perhaps we could just change it, because the return convention 
is the same in both cases.

Cheers,
	Simon



More information about the Cvs-ghc mailing list