[Haskell-cafe] what is the magic hash?

wren ng thornton wren at freegeek.org
Wed Sep 24 00:24:37 EDT 2008


Jason Dusek wrote:
> Derek Elkins <derek.a.elkins at gmail.com> wrote:
>> Jason Dusek wrote:
>>> It is not much covered in the docs. It has something to do
>>>   with magic triggered by a postfix octothorpe?
>> All it does is allow them in identifiers.
> 
>   That's it? So it's for use in conjunction with primitive
>   types, I guess (those seem to be denoted like 'Int#')?
> 
>   With the fancy name and the absence of documentation, I
>   assumed it must be really special.


The octothrorp is for the unboxed/unlifted kind in GHC. In addition to 
the postfix usage it's also used for unboxed tuples (# , #) (# ,, #)... 
which don't actually exist[1], and also as a kinding symbol for these 
native types (as opposed to the * symbol for the usual boxed/lifted kind).

There are various limitations on where you can use types in the # kind, 
which should be in the GHC docs. Unless you're trying to hammer the last 
fraction of performance out of GHC, it's best to leave them alone and 
trust the optimizer to reorganize code to use them. These types of 
performance gains are often more portably gained by using bang patterns 
or strict fields, FWIW.


[1] Each field of the unboxed tuple is stored in a register (or 
otherwise fed directly to its destination).

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list