Data encoding library

Magnus Therning magnus at
Sun Oct 14 12:50:59 EDT 2007

On Sun, Oct 14, 2007 at 12:55:28 +0200, apfelmus wrote:
> 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

There is no particular need for separate modules, except that in the
current version  there would be name clashes.

>> 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

A similar result could be gotten by using phantom types, right?  But
then there must be some way of liberating the result.  I'm not sure yet
whether they are worth it.

AFAIU the example from above then changes to

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

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

I will for sure change the result of decode to deal with failures.

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

For some encodings there are standard ways of splitting an encoded
string over several lines.  Unfortunately it's not always as simple as
just splitting a string at a particular length.  Uuencode is the most
complicated I've come across so far.  That's what chop/unchop is for.


Magnus Therning                             (OpenPGP: 0xAB4DFBA4)             Jabber:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url :

More information about the Libraries mailing list