Hi

hPutInt h = hPutStr h . map chr . map (0xff .&.)
                      . take 4 . iterate (`shiftR` 8)

hGetInt h = replicateM 4 (hGetChar h) >>=
            return . foldr (\i d -> i `shiftL` 8 .|. ord d) 0

This of course assumes that a Char is read/written as a single low-order
byte without any conversion.  But you'd have to assume a lot more if you
started messing with pointers.  (Strange, somehow I get the feeling, the
above is way too easy to be the answer you wanted.)

It's exactly the answer I was hoping for!

Thanks

Neil
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to