Unpacking across modules

Scott Dillard sedillard at ucdavis.edu
Mon Nov 12 17:02:25 EST 2007


What is the interaction between the UNPACK pragma and modules? I've
attached a small test case where a datatype is unpacked when it and
its associated functions are defined in the same file in which they
are used, but it is not unpacked if the definitions are given in
another module. There are two versions of the data type, a monomorphic
one, defined by:

> data Vec3 = Vec3 Double Double Double

and a polymorphic, recursive one, defined by

> data C a b = C a b

With the following typedef to make them equivalent

> type Vec3 = C Double (C Double (C Double () ))

In the actual file, they're both appropriately annotated with bangs
and UNPACK pragmas. The mono datatype is successfully unpacked in both
cases, when it is defined in the same file and in a different file.
The poly datatype is only unpacked when it is defined in the same

To see the behavior, compile the attached files with -DMONO_SAME,
-DMONO_OTHER, -DPOLY_SAME and -DPOLY_OTHER. In all cases except
POLY_OTHER, the program runs in constant space, and in time that is
quite competitive with C. (Nice work guys!) However, for POLY_OTHER
you will likely have to kill it. The only other flag I used is -O2.

Please let me know there's something I'm missing here. Is there a
reason why this data type cannot be unboxed across modules? Or is this
a bug?


PS: Also, when the INLINE pragma is used with the Storable instance
for the polymorphic data type, it causes heap explosion, even in the
same file. Any thoughts here?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Unpacked.hs
Type: text/x-haskell
Size: 3119 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20071112/8a35a2f2/Unpacked.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OtherM.hs
Type: text/x-haskell
Size: 857 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20071112/8a35a2f2/OtherM.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OtherP.hs
Type: text/x-haskell
Size: 1391 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20071112/8a35a2f2/OtherP.bin

More information about the Glasgow-haskell-users mailing list