[Haskell-cafe] Just for a laugh...
Dan Doel
dan.doel at gmail.com
Thu May 31 17:08:01 EDT 2007
On Thursday 31 May 2007, Andrew Coppin wrote:
> If you're bored... can you come up with a solution to this?
>
> http://warp.povusers.org/ProgrammingChallenge.html
>
> (Obviously a pretty silly challenge, but hey.)
With some help from int-e in irc:
> {-# OPTIONS_GHC -fglasgow-exts #-}
> import GHC.Base
> import GHC.Word
> import GHC.Exts
> import Numeric
> import Data.Char
> doubleToBits (D# d) = W64# (unsafeCoerce# d)
> main = interact $ unlines
> . map (pad . (\x -> showIntAtBase 2 intToDigit x "")
> . doubleToBits . read)
> . lines
> where pad l = replicate (64 - length l) '0' ++ l
I suspect that that doesn't respect the endianness of the machine like the C++
does, though.
-- Dan
More information about the Haskell-Cafe
mailing list