Err, is this just for academic purposes, or is there some deeper reason you want an Enum instance of String? That will dictate how to define the functions. For example, you could just as easily imagine other definitions of fromEnum, such as:
fromEnum = read . concatMap (show . ord)
Why? *shrug*...the types match. So...you need to figure out why you're doing what you're doing before you can really figure out what you're doing.
Hope this helps!
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