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@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Attachment: PGP.sig
Description: Signierter Teil der Nachricht

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to