Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Bulat Ziganshin
Hello Andrew, Thursday, May 31, 2007, 11:47:28 PM, you wrote: (Otherwise... wasn't there some library somewhere for serialising values in binary?) Binary, AltBinary (see latest HCAR), just an example using AltBinary: main = do let s = encode (1.1::Float) -- s has type String

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Jules Bean
Donald Bruce Stewart wrote: let s = encode (1.1 :: Float) :t s s :: Data.ByteString.Lazy.ByteString s LPS [\NUL\NUL\140\204\205\255\255\255\255\255\255\255\233] decode s :: Float 1.1 But doesn't Data.Binary serialise to a guaranteed representation, i.e.

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Donald Bruce Stewart
bulat.ziganshin: Hello Andrew, Thursday, May 31, 2007, 11:47:28 PM, you wrote: (Otherwise... wasn't there some library somewhere for serialising values in binary?) Binary, AltBinary (see latest HCAR), just an example using AltBinary: main = do let s = encode (1.1::Float)

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Donald Bruce Stewart
jules: Donald Bruce Stewart wrote: let s = encode (1.1 :: Float) :t s s :: Data.ByteString.Lazy.ByteString s LPS [\NUL\NUL\140\204\205\255\255\255\255\255\255\255\233] decode s :: Float 1.1 But doesn't Data.Binary serialise to a guaranteed

Re[2]: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Bulat Ziganshin
Hello Jules, Friday, June 1, 2007, 3:02:33 PM, you wrote: machine-independent? Whereas this (stupid) question explicitly asked for *your particular hardware's* floating point rep. there is castSTUArray function which is widely used exactly for this purpose. look for examples of its usage in

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Andrew Coppin
David Roundy wrote: Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. I've always been puzzled by this one... how does unsafePerformIO circumvent the type system? I don't understand. ___

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread David Roundy
On Fri, Jun 01, 2007 at 07:28:07PM +0100, Andrew Coppin wrote: David Roundy wrote: Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. I've always been puzzled by this one... how does unsafePerformIO circumvent the type system? I don't

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Andrew Coppin
Donald Bruce Stewart wrote: See also the older NewBinary, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/NewBinary-0.1 Now that's just ironic... Incidentally, I've been thinking. You *might* want the binary representation of things if you were going to, say, compress or

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Andrew Coppin
David Roundy wrote: On Fri, Jun 01, 2007 at 07:28:07PM +0100, Andrew Coppin wrote: David Roundy wrote: Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. I've always been puzzled by this one... how does unsafePerformIO

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread David Roundy
On Fri, Jun 01, 2007 at 07:39:32PM +0100, Andrew Coppin wrote: David Roundy wrote: On Fri, Jun 01, 2007 at 07:28:07PM +0100, Andrew Coppin wrote: David Roundy wrote: Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. I've

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Dan Doel
On Friday 01 June 2007, Andrew Coppin wrote: David Roundy wrote: Note also that you can use unsafePerformIO to safely get pure functions doing both these operations. I've always been puzzled by this one... how does unsafePerformIO circumvent the type system? I don't understand. import

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread rossberg
David Roundy wrote: On Fri, Jun 01, 2007 at 07:39:32PM +0100, Andrew Coppin wrote: No, I mean... how could you use unsafePerformIO to perform a typecast? I don't see a way to do that. Then I'm confused. What typecast are you talking about? cast :: a - b cast x = unsafePerformIO (do

Re: [Haskell-cafe] Just for a laugh...

2007-06-01 Thread Donald Bruce Stewart
andrewcoppin: Donald Bruce Stewart wrote: See also the older NewBinary, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/NewBinary-0.1 Now that's just ironic... Incidentally, I've been thinking. You *might* want the binary representation of things if you were going

[Haskell-cafe] Just for a laugh...

2007-05-31 Thread Andrew Coppin
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.) My first instinct was to use Data.Bits - but I see no instance for Double. (Presumably because performing bitwise operations on a

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread David House
On 31/05/07, Andrew Coppin [EMAIL PROTECTED] wrote: If you're bored... can you come up with a solution to this? Try using floatToDigits: http://haskell.org/ghc/docs/latest/html/libraries/base/Numeric.html#v%3AfloatToDigits floatToDigits takes a base and a non-negative RealFloat number, and

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Tomasz Zielonka
On Thu, May 31, 2007 at 08:47:28PM +0100, 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.) I fail to see what this has to do with expressive power, which it's

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Andrew Coppin
Tomasz Zielonka wrote: On Thu, May 31, 2007 at 08:47:28PM +0100, 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.) I fail to see what this has to do with

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Dan Doel
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

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread John Meacham
On Thu, May 31, 2007 at 08:47:28PM +0100, Andrew Coppin wrote: My first instinct was to use Data.Bits - but I see no instance for Double. (Presumably because performing bitwise operations on a Double is a pretty odd thing to want to do.) So my next guess is to do some bizzare type system

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Tomasz Zielonka
On Thu, May 31, 2007 at 08:47:28PM +0100, 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.) My first instinct was to use Data.Bits - but I see no instance for

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Brandon S. Allbery KF8NH
On May 31, 2007, at 15:47 , Andrew Coppin wrote: If you're bored... can you come up with a solution to this? http://warp.povusers.org/ProgrammingChallenge.html Is it me, or does this look like a job for Data.Binary? -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread Creighton Hogg
On 5/31/07, Brandon S. Allbery KF8NH [EMAIL PROTECTED] wrote: On May 31, 2007, at 15:47 , Andrew Coppin wrote: If you're bored... can you come up with a solution to this? http://warp.povusers.org/ProgrammingChallenge.html Is it me, or does this look like a job for Data.Binary? It's not

Re: [Haskell-cafe] Just for a laugh...

2007-05-31 Thread David Roundy
On Thu, May 31, 2007 at 11:36:54PM +0200, Tomasz Zielonka wrote: You can imitate the C++ code using the FFI libraries: import Foreign.Storable import Foreign import Data.Word import Data.Bits getDoubleBits :: Double - IO String getDoubleBits d = alloca $ \ptr -