Unpack primitive types by default in data

Roman Leshchinskiy rl at cse.unsw.edu.au
Fri Feb 17 09:52:17 CET 2012


Johan Tibell wrote:
> Hi all,
>
> I've been thinking about this some more and I think we should
> definitely unpack primitive types (e.g. Int, Word, Float, Double,
> Char) by default.
>
> The worry is that reboxing will cost us, but I realized today that at
> least one other language, Java, does this already today and even
> though it hurts performance in some cases, it seems to be a win on
> average. In Java all primitive fields get auto-boxed/unboxed when
> stored in polymorphic fields (e.g. in a HashMap which stores keys and
> fields as Object pointers.) This seems analogous to our case, except
> we might also unbox when calling lazy functions.

I'm not convinced that this is a good idea because it doesn't treat all
types equally. The comparison with Java is problematic, IMO, because in
Java 'int' is always called 'int' whereas in Haskell, it might be called
many different things.

To better understand the proposal, which of the types below would you want
to be unboxed automatically?

data A = A Int#
newtype B = B A
data C = C !B
data D = D !C
data E = E !()
data F = F !D

Roman






More information about the Glasgow-haskell-users mailing list