winterkoninkje: shadowcrane (clean) (Default)

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.


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.


Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
Account name:
If you don't have an account you can create one now.
HTML doesn't work in the subject.


If you are unable to use this captcha for any reason, please contact us by email at

Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

April 2017

2 345678
161718192021 22


Page generated 26 May 2017 01:06 pm
Powered by Dreamwidth Studios