prelude-safeenum 0.1.0

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.

Description

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 pred , succ , fromEnum , and toEnum to 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: enumDownFrom , enumDownFromTo One of the big problems with the partiality of pred is 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 Ord ordering (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 Float and Double which are highly problematic and often confuse newcomers to Haskell. Unfortunately, this rigor does render the instance for Ratio problematic. However, Ratio instances 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 Ord . The obscure order required for well-defined enumeration of Ratio is provided.

Links