[Haskell-cafe] Trouble understanding NewBinary

ChrisK chrisk at MIT.EDU
Fri Oct 7 18:43:36 EDT 2005


In GHC.Exts are the definitions

data Char = C# Char#
data Int = I# Int#
data Integer = S# Int# | J# Int# ByteArray#
data Double = D# Double#
data Float = F# Float#

Found with ghci using

:m + GHC.Exts

:browse GHC.Exts


Joel Reymont wrote:
> Folks,
> 
> In http://www.n-heptane.com/nhlab/repos/NewBinary/NewBinary/Binary.hs 
> there's the following bit of code. What are the I#, S# and J#?
> 
> instance Binary Integer where
>     put_ bh (S# i#) = do putByte bh 0; put_ bh (I# i#)
>     put_ bh (J# s# a#) = do
>      p <- putByte bh 1;
>     put_ bh (I# s#)
>     let sz# = sizeofByteArray# a#  -- in *bytes*
>     put_ bh (I# sz#)  -- in *bytes*
>     putByteArray bh a# sz#
> 
>     get bh = do
>     b <- getByte bh
>     case b of
>       0 -> do (I# i#) <- get bh
>           return (S# i#)
>       _ -> do (I# s#) <- get bh
>           sz <- get bh
>           (BA a#) <- getByteArray bh sz
>           return (J# s# a#)
> 
>     Thanks, Joel
> 
> -- 
> http://wagerlabs.com/idealab
> 
> 
> 
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list