Aaron Denney wrote:
On 2007-11-17, Andrew Coppin <[EMAIL PROTECTED]> wrote:
  pack8into16 :: [Word8] -> Word16
  pack8into32 :: [Word8] -> Word32
  unpack16into8 :: Word16 -> [Word8]
  unpack32into8 :: Word32 -> [Word8]
  pack8into16s :: [Word8] -> [Word16]
  pack8into32s :: [Word8] -> [Word32]
  etc.

I had to write all these myself, by hand, and then check that I got everything the right way round and so forth. (And every now and then I find an edge case where these functions go wrong.)

Well, you know, some of these are really the wrong signatures:

pack8into16 :: (Word8, Word8) -> Word16
pack8into32 :: (Word8, Word8, Word8, Word8) -> Word32
unpack16into8 :: Word16 -> (Word8, Word8)
unpack32into8 :: Word32 -> (Word8, Word8, Word8, Word8)

curry the above to taste.

Yeah, but

 unpack16into8s = concatMap unpack16into8

;-)

Now if you just define some function splitN :: Int -> [x] -> [[x]] (I'm sure we've debated why this isn't defined already...), we can even write

 pack8into16s = map pack8into16 . splitN 16

And so we continue...

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to