[Haskell-beginners] Meaning of '!' in record defintion? UNPACK?

Thomas Davie tom.davie at gmail.com
Thu Feb 26 05:48:09 EST 2009


On 26 Feb 2009, at 11:42, Erik de Castro Lopo wrote:

> Hi all,
>
> I'm looking at some code that defines a record:
>
>    data Position =
>           Position { posOffset :: {-# UNPACK #-} !Int
>                    , posRow :: {-# UNPACK #-} !Int
>                    , posColumn :: {-# UNPACK #-} !Int
>                    }
>
> What does the the exclamation mark mean? And UNPACK?

The ! means "strict" – i.e. don't store a thunk for an Int here, but  
evaluate it first.

The {-# UNPACK #-} tells the compiler that it can unpack the Int –  
meaning that a Position will be neatly packed into 12 bytes.

Bob


More information about the Beginners mailing list