[Haskell-cafe] ANN: convertible (first release)
Daniel Schüssler
anotheraddress at gmx.de
Tue Feb 10 20:04:20 EST 2009
Hello,
it is a real code snippet, but I failed to include the necessary pragma (which
is:
{-# OPTIONS_GHC -fglasgow-exts #-}
or
{-# OPTIONS_GHC -XMagicHash #-}
at the beginning of the file).
the "#" suffix is for unboxed types:
http://www.haskell.org/ghc/docs/latest/html/users_guide/primitives.html
http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#magic-hash
Greetings,
Daniel
On Wednesday 11 February 2009 00:19:56 Dylan Tisdall wrote:
> Maybe I'm just a noob falling for someone's joke here, but I can't
> make that sample, or anything else I tried with "#" on the end of
> names, to compile with ghci. In the example below, I get a parse error
> at the line defining d2f. Is this a real code snippet?
>
>
> Cheers,
> Dylan
>
> On Feb 10, 2009, at 2:46 AM, Daniel Schüssler wrote:
> > Hi,
> >
> > On Wednesday 28 January 2009 04:30:07 John Goerzen wrote:
> >> On Tue, Jan 27, 2009 at 09:41:30PM -0500, wren ng thornton wrote:
> >>> I once again point out that realToFrac is *wrong* for converting
> >>> from
> >>> Float or Double.
> >>>
> >>>> realToFrac (1/0::Float) ::Double
> >>>
> >>> 3.402823669209385e38
> >>
> >> Yes, I understand what you are saying and agree with you. But there
> >> is nothing better in the standard library
> >
> > don't know whether you consider GHC as standard library, but if you
> > do...:
> >
> > import GHC.Types
> > import GHC.Prim
> >
> > -- | Double to Float
> > d2f (D# d) = F# (double2Float# d)
> >
> > -- | Float to Double
> > f2d (F# f) = D# (float2Double# f)
> >
> >
> > ghci> f2d (1/0)
> > Infinity
> > it :: Double
> >
> > :)
> >
> > --
> > Daniel
> > _______________________________________________
> > 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