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
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
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
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?