Top-level bindings for unlifted types

Neil Mitchell ndmitchell at
Tue Nov 13 14:35:33 EST 2007


> Top-level unboxed values would then
> behave just like #define constants, in fact.  This is certainly possible,
> it would just add complexity to the compiler in various places.

Yes, that was all I was thinking of. I'm not suggesting that these
things actually get implemented, but it did seem a strange restriction
that it would have been impossible to define something like realWorld#
in Haskell without baking it into the compiler.

> What would you expect to happen for this?
> fib :: Int -> Int#
> fib n = ...
> x :: Int#
> x = fib 100#
> 'x' cannot be bound to a thunk.  So the top-level computation would have to be evaluated eagerly.  But when?  Perhaps when the program starts?

Yes, when the program starts seems perfectly sensible - and mirrors
what happens in C, I believe.

My particular use of this construct was to introduce a little bit of
abstraction so that the same code could be compiled with GHC and Hugs
simply by switching in a different set of definitions - and still
perform optimally in GHC. But some CPP does just as well :-)



More information about the Glasgow-haskell-users mailing list