Enum, Bounded, and Arithmetic Sequences
Ferenc Wagner
wferi@afavant.elte.hu
Wed, 25 Jun 2003 12:16:59 +0200
Johannes Waldmann <joe@informatik.uni-leipzig.de> writes:
>> x :: Foo <- [ .. ]
>
> A related point: the Haskell definition states that
For any type that is an instance of class Bounded as well as
Enum, the following should hold:
>
>> enumFrom and enumFromThen should be defined with an implicit bound, thus:
>> enumFrom x = enumFromTo x maxBound
> I think this should be enforced -
> the *only* method in Enum should be `enumFromTo'.
>
> If one writes [ x .. ], then the compiler expands this to
> `enumFromTo x maxBound', and therefore adds a `Bounded' constraint.
> Likewise, [ .. y ] expands to `enumFromTo minBound y',
No, "half" infinite list like [1..] are useful.
> and [ .. ] to `enumFromTo minBound maxBound' .
This I would not mind, I can not think of another reasonable
translation. But why not define
elements :: (Enum a, Bounded a) => [a]
elements = [minBound .. maxBound]
instead?
> PS: and enumFromThenTo should just be removed, alongside n+k patterns :-)
Or preferably the Floating and Double Enum instances...
Feri.