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

JustinGoguen adekoba at hamiltonshells.ca
Mon Dec 29 22:25:42 EST 2008

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

More information about the Haskell-Cafe mailing list