GHC.Types consturctors with #
David Peixotto
dmp at rice.edu
Mon Nov 1 14:22:15 EDT 2010
Hi Larry,
GHC allows you to work with unboxed types. Int# is the type of unboxed ints. I# is a normal data constructor. So we can see that GHC represents a (boxed) Int as a normal algebraic data type
data Int = I# Int#
which says that an Int is a type with a single constructor (I#) that wraps a machine integer (Int#). By convention, unboxed types use a # in their name.
You can find more info about unboxed types here: http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/primitives.html#glasgow-unboxed
To work with unboxed types in your code (or ghci) you need the MagicHash extension: http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/syntax-extns.html#magic-hash
$ ghci -XMagicHash
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> import GHC.Types
Prelude GHC.Types> I# 5#
5
Prelude GHC.Types>
-David
On Nov 1, 2010, at 12:40 PM, Larry Evans wrote:
> http://www.haskell.org/ghc/docs/6.10.2/html/libraries/ghc-prim/GHC-Types.html
>
> contains:
>
> data Int = I# Int#
>
> What does I# Int# mean? I've tried a simple interpretation:
>
> Prelude GHC.Types> I# 5#
>
> <interactive>:1:5: parse error (possibly incorrect indentation)
> Prelude GHC.Types>
>
> but obviously that failed :(
>
> TIA.
>
> -Larry
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
More information about the Glasgow-haskell-users
mailing list