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

Adrian Neumann aneumann at inf.fu-berlin.de
Tue Dec 30 10:01:56 EST 2008


Better would be

[] = 0
['a'] = 1
['b'] = 2
...
['z'] = 26
['a','a'] = 27
['a','b'] = 28

(asuming Char = ['a'..'z'])

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.
>
> For example, running fromEnum on the string "d" will result in 100.  
> But when we
> pass 100 to toEnum, it does not know if it should treat 100 as "d"  
> or "22"
> (fromEnum '2' == 50).
>
> Source so far:
>
> instance Enum [Char] where
>     succ = undefined
>     pred = undefined
>     toEnum n = undefined -- what to do?
>     fromEnum xs = sum $ map fromEnum xs
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 194 bytes
Desc: Signierter Teil der Nachricht
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081230/df67daf6/PGP.bin


More information about the Haskell-Cafe mailing list