The prelude-safeenum package offers a safe alternative to the Prelude's
Enum class in order to render it safe. While we're at it, we also generalize the notion of enumeration to support types which can only be enumerated in one direction.
The prelude-safeenum package offers an alternative to the notion of enumeration provided by the Prelude. For now it is just a package, but the eventual goal is to be incorporated into haskell prime. Some salient characteristics of the new type-class hierarchy are:
- Removes partial functions
- The Haskell Language Report section 6.3.4 defines
toEnumto be partial functions when the type is
Bounded, but this is unacceptable. The new classes remove this problem by correcting the type signatures for these functions.
- Generalizes the notion of enumeration
- Rather than requiring that the type is linearly enumerable, we distinguish between forward enumeration (which allows for multiple predecessors) and backward enumeration (which allows for multiple successors).
- Adds new functions:
- One of the big problems with the partiality of
predis that there is no safe way to enumerate downwards since in the border case
enumFromThen x (pred x)will throw an error rather than evaluating to
[x]as desired. These new functions remove this problem.
- Removes the requirement...
- ...that the enumeration order coincides with the
Ordordering (if one exists). Though, of course, it's advisable to keep them in sync if possible, for your sanity.
- Ensures that the notion of enumeration is well-defined
- This much-needed rigor clarifies the meaning of enumeration. In addition, it rules out instances for
Doublewhich are highly problematic and often confuse newcomers to Haskell. Unfortunately, this rigor does render the instance for
Ratioinstances can be provided so long as the base type is enumerable (and
Integral, naturally); but they must be done in an obscure order that does not coincide with
- The obscure order required for well-defined enumeration of
- Homepage: http://code.haskell.org/~wren/
- Hackage: http://hackage.haskell.org/package/prelu
- Darcs: http://community.haskell.org/~wren/prelu
- Haddock: Darcs version