Err, Lennart, doesn't your implementation
a) write C doubles (even for Float)
b) attach extra information to the file
That is in the C sense you don't read/write a raw stream of floats. I
assume that what David wanted was something which would read the stream
of floats his C program generated rather than just an example of
using readBin/showBin in Haskell?
I can't quite work out your Binary format, but 7 32-bit words to
write 2 32-bit floats probably isn't what David was hoping for...
Kevin
> > I need is an example of
> > directly using binary mode IO. Suppose I have a file containing a stream
> > of floats. Can anyone show me a Haskell program that just prints out the
> > floats as a list, parsing the input using readBin??
> Aha, sorry that I misunderstood your question. Here are is one program to
> produce a file with some floats (64 bit) and another to read that file.
>
> --- Run this to get the (non-portable) file "floats".
> main = writeBinFile "floats" bfloats abort done
> where bfloats = showBin floats nullBin
> floats :: [Double]
> floats = [sin x | x <- [0.0, 0.1 .. 1.0]]
>
>
> --- Run this to read and print the file "floats".
> main = readBinFile "floats" abort (\bfloats ->
> let floats :: [Double]
> floats = fst (readBin bfloats)
> in appendChan stdout (show floats ++ "\n") abort done)
>
> I've tested these using hbc.
>
> -- Lennart