
Simon Marlow wrote:
On 06 October 2004 00:53, John Meacham wrote:
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? :-)
Would it really be correct to translate it to Int#? AFAIK, unboxed values may not contain bottom while a data type most certainly can. I would imagine translating it to Int, and then relying on GHC's optimiser to optimize this into Int# whenever possible. /Josef