GHC.Types consturctors with #

http://www.haskell.org/ghc/docs/6.10.2/html/libraries/ghc-prim/GHC-Types.htm... 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

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#glas... 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#ma... $ 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.htm...
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@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Monday 01 November 2010 18:40:00, 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 :(
Needs ghci> :set -XMagicHash then it will print 5. GHC uses the magic hash to denote unboxed raw types and data constructors using those. The point is, I think, making them stand out and avoiding accidental use (most of the time you're fine using the regular boxed things and letting GHC unbox them, but for when that's not good enough, you can use the low- level stuff directly).
TIA.
-Larry
participants (3)
-
Daniel Fischer
-
David Peixotto
-
Larry Evans