[Haskell-cafe] instance Enum [Char] where ...

Thomas Davie tom.davie at gmail.com
Tue Dec 30 10:51:36 EST 2008


Am 30.12.2008 um 04:25 schrieb JustinGoguen:

> I am having difficulty making [Char] an instance of Enum. fromEnum  
> is easy
> enough: map fromEnum to each char in the string and take the sum.  
> However,
> toEnum has no way of knowing what the original string was.

The problem you're having is that your implementation does not  
correctly enumerate lists of characters – in order to do so correctly,  
you must not create the clashes you get with (for example "ab" and  
"ba").

I'd suggest rethinking how you would enumerate such strings.

Bob


More information about the Haskell-Cafe mailing list