Am Samstag, 29. November 2003 23:58 schrieb [EMAIL PROTECTED]:
> G'day all.
>
> Quoting Wolfgang Jeltsch <[EMAIL PROTECTED]>:
> > I think, I have already said the following on this list. I would also like
> > to have different character types for different subsets of Char (e.g.,
> > ASCII) and a class Character which the different character types are
> > instances of.
>
> As a matter of interest, what might some of the methods of this class be?
> ord and chr are two obvious choices.  What else?

Hello,

I have such a Character class in my Seaweed library. You may have a look at
    http://cvs.sf.net/viewcvs.py/seaweed/code/Seaweed/Core/Characters.hs
and
    http://cvs.sf.net/viewcvs.py/seaweed/code/Seaweed/Core/Characters/ASCII.hs

The class has two methods, toCharacterMonad and fromCharacter, converting 
between ordinary Chars and instances of the Character class. The second 
function uses monads for error handling; it yields return <something> if 
conversion was successful and fail <something> if not. Several functions are 
implemented on top of these two methods.

I created the Character class since I'm working with text-based network 
protocols and text-based file formats (like XML) where characters are often 
restricted to certain sets. I wanted to have such restrictions forced by the 
compiler.

IMHO, it would be nice to also have some support for the Character class by 
the syntax of Haskell. I could imagine declarations of the form
    chartype ASCIIPrintable = ' ' .. '~'
    chartype ASCIICtrl = '\000' .. '\037' | '\177'
A char literal like 'A' could denote not only a Char value but a value of any 
type which is an instance of Character. A default mechanism similar to Num 
could be introduced also with characters.

> Cheers,
> Andrew Bromage

Wolfgang

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to