Data encoding library

apfelmus apfelmus at
Sun Oct 14 06:55:28 EDT 2007

Magnus Therning wrote:
> I've just created the page
> (there are no links
> into it at the moment).
> Any comments on what I've written there?
> Are the locations in the hierarchy good?

Nice, but do you really need separate modules for each encoding? I mean, 
Ashely's proposal

> 2. Codecs, i.e. encoder/decoder pairs such as charset converters
>   data Codec base derived = MkCodec
>   {
>     encode :: derived -> base,
>     decode :: base -> Maybe derived -- or other Monad
>   }
>   utf8 :: Codec [Word8] String
>   xml :: Codec String XML 

from the recent thread

would fit the bill perfectly, wouldn't it? In other words, encodings are 
just pairs of functions, nothing complicated

   base16    :: Codec String [Word8] -- decode Strings to Word8
   base32    :: Codec String [Word8]
   base64    :: ...
   base64url ::
   uuencode  ::

For more documentation in the types, a type synonym may come in very handy

   type ASCII = String
   base16    :: Codec ASCII [Word8]

Want to encode an example? Here you go

   encode base16 [0xde,0xad,0xbe,0xef] :: ASCII

Btw, it is essential that  decode  may fail on bad input!

Also, I don't have a clue about what  chop  and  unchop  are supposed to do.


More information about the Libraries mailing list