
29 Dec
2008
29 Dec
'08
10:25 p.m.
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