Bools are not unboxed

Simon Marlow simonmar at
Wed Oct 6 06:07:18 EDT 2004

On 06 October 2004 00:53, John Meacham wrote:

> On Tue, Oct 05, 2004 at 01:48:30PM +0100, Simon Marlow wrote:
>> It would probably be better to return 0#/1# instead of a Bool from
>> the comparison primops, because this would expose slightly more
>> detail to the simplifier and might result in slightly better code in
>> some cases (but no dramatic improvements).  It would also let us
>> remove a bit of complexity from the code generator.
> This seems like it could be nicely generalized such that all
> enumeration types unbox to the unboxed integer of their offset. so
> data Perhaps = Yes | Maybe | No
> can unbox to an Int# with 0# == Yes 1# == Maybe and 2# == No.

Yes, a strict enumeration should be implemented as an Int#, both in the
strictness analyser and also when you {-# UNPACK #-} a constructor
field.  This is something we'd like to try, but haven't got around to it
yet.  Maybe a good bite-sized project for a budding GHC hacker? :-)

> Then we get the Bool optimization for free.

The original question was about the primitive comparisons, so I think
we'd still have to change the types of these primitives.  Furthermore
we'd probably have to teach the compiler that the result of the
comparison primops is compatible with a strict Bool.  It wouldn't be
entirely free.


More information about the Glasgow-haskell-users mailing list