[Haskell-cafe] Small question

Stefan O'Rear stefanor at cox.net
Thu Aug 9 16:54:45 EDT 2007


On Thu, Aug 09, 2007 at 09:27:23PM +0100, Andrew Coppin wrote:
> OOC, in what way is Bool not "primitive enough"? You mean because it's an 
> algebraic data type, rather than a bunch of bits in the machine? For that 
> matter, just how much space does such a type typically use?

Yes.

data Bool = False | True

In general, GHC doesn't do "unboxing".  Instead it has a simpler and
more general approach, where it passes the fields of a
single-constructor type instead of the type itself; this is as good as
true unboxing in most of the interesting cases:

data Int = I# Int#
data Float = F# Float#
data Double = D# Double#
data Char = C# Char#
data Ptr = Ptr Addr#
...

but not always:

data Bool = False | True
data Integer = S# Int# | J# ByteArray# Int#

As far as actual heap usage goes, GHC creates single static values for
all 0-argument constructors; so all Bool WHNFs are one of two addresses,
one for True and one for False.  But GHC isn't quite smart enough for
the -funbox-strict-fields mechanism to understand this...

> (Questions, questions, so many questions...)

I like answering them. :)

Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070809/1094fbcd/attachment.bin


More information about the Haskell-Cafe mailing list