Unboxed singleton tuples

Roman Leshchinskiy rl at cse.unsw.edu.au
Fri Aug 15 00:01:38 EDT 2008


On 15/08/2008, at 07:11, Tim Chevalier wrote:

> While reading some Core code, I noticed a function whose return type
> was (# State# RealWorld #). I was curious why unboxed tuples of arity
> 1 would exist, so I dug around in the GHC sources and found that they
> are used when desugaring foreign calls, as per the comment at the
> beginning of boxResult in deSugar/DsCCall.lhs. But I still don't
> understand -- what's the difference between (# foo #) and foo?

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. (# a #) is  
basically the same as

   data Id a = Id a

but without the boxing.

Roman




More information about the Cvs-ghc mailing list