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

2008-12-30 Thread Adrian Neumann
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

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

2008-12-30 Thread Thomas Davie
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. The problem you're having is that

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

2008-12-29 Thread 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

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

2008-12-29 Thread Andrew Wagner
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?