Unpacking multi-type constructors

Louis Wasserman wasserman.louis at gmail.com
Mon Jul 20 19:19:35 EDT 2009

I think this is a feasible idea.  Whether this is in fact a good idea is an
entirely separate question, however, and I want feedback.

Currently, I believe that an UNPACK pragma used on a multi-constructor type
has no effect.  For example,

data Node = Node Int {-# UNPACK #-} !(Maybe Node) {-# UNPACK #-} !(Maybe

is the same as

data Node = Node Int !(Maybe Node) !(Maybe Node)

What I'd like is for this to translate into four constructors, one for each
combination of constructors for the UNPACK'd fields:

data Node = Node0 Int -- Nothing, Nothing
| Node1 Int Node -- Just, Nothing
| Node2 Int Node -- Nothing, Just
| Node3 Int Node Node -- Just, Just
The primary counterargument I can think of is that this can result in a
single-constructor type being turned into a multi-constructor type, which
runs the risk of interfering with GHC's sexcellent handling of
single-constructor types.

The countercounterargument is, of course, that the {-# UNPACK #-} pragma
already behaves differently depending on the single-constructorness of the
underlying type, and that the obligation is already on the programmer to
check such things.

For reference, could somebody point me to the place in GHC that currently
takes care of {-# UNPACK #-} pragmas, so I could -- for instance -- figure
out whether or not there's another reason that this idea isn't in place

Louis Wasserman
wasserman.louis at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20090720/191fa2a9/attachment.html

More information about the Glasgow-haskell-users mailing list