discrete-0.1.0.0: replacement for enum

Safe HaskellNone
LanguageHaskell2010

Data.Discrete

Synopsis

Documentation

class Discrete a where Source #

A Discrete type is a set X with at least one element, along with two functions, succ :: X -> Maybe X and pred :: X -> Maybe X, such that all inhabitants of the set X can be constructed given at least a single element of the set and these two functions. The following must hold:

pred >=> succ >=> pred = pred
succ >=> pred >=> succ = succ

This means that Int is a discrete type, because given any x :: Int, one can construct any other Int with the following functions:

succ x = if x == maxBound then Nothing else Just (x + 1)
pred x = if x == minBound then Nothing else Just (x - 1)

This also means that something like Double is not a discrete type, because there are no such functions succ and pred that given any value of type Double can allow the construction of all values of type Double.

Discrete acts as a replacement for Enum. The motivation for Discrete is two-fold: firstly, totality of all typeclass instances, and secondly, that Enum is a typeclass that does too many things, and does them poorly. If succ or pred are called on maxBound or minBound, respectively, the result will be Nothing.

Minimal complete definition

pred, succ

Methods

succ :: a -> Maybe a Source #

pred :: a -> Maybe a Source #

Instances
Discrete Bool Source # 
Instance details

Defined in Data.Discrete

Discrete Char Source # 
Instance details

Defined in Data.Discrete

Discrete Int Source # 
Instance details

Defined in Data.Discrete

Discrete Int8 Source # 
Instance details

Defined in Data.Discrete

Discrete Int16 Source # 
Instance details

Defined in Data.Discrete

Discrete Int32 Source # 
Instance details

Defined in Data.Discrete

Discrete Int64 Source # 
Instance details

Defined in Data.Discrete

Discrete Integer Source # 
Instance details

Defined in Data.Discrete

Discrete Ordering Source # 
Instance details

Defined in Data.Discrete

Discrete Word Source # 
Instance details

Defined in Data.Discrete

Discrete Word8 Source # 
Instance details

Defined in Data.Discrete

Discrete Word16 Source # 
Instance details

Defined in Data.Discrete

Discrete Word32 Source # 
Instance details

Defined in Data.Discrete

Discrete Word64 Source # 
Instance details

Defined in Data.Discrete

Discrete () Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: () -> Maybe () Source #

pred :: () -> Maybe () Source #

Discrete a => Discrete (Maybe a) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: Maybe a -> Maybe (Maybe a) Source #

pred :: Maybe a -> Maybe (Maybe a) Source #

Integral a => Discrete (Ratio a) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: Ratio a -> Maybe (Ratio a) Source #

pred :: Ratio a -> Maybe (Ratio a) Source #

Discrete a => Discrete (Identity a) Source # 
Instance details

Defined in Data.Discrete

(Bounded a, Bounded b, Discrete a, Discrete b) => Discrete (Either a b) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: Either a b -> Maybe (Either a b) Source #

pred :: Either a b -> Maybe (Either a b) Source #

(Bounded b, Discrete a, Discrete b) => Discrete (a, b) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: (a, b) -> Maybe (a, b) Source #

pred :: (a, b) -> Maybe (a, b) Source #

Discrete a => Discrete (Const a b) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: Const a b -> Maybe (Const a b) Source #

pred :: Const a b -> Maybe (Const a b) Source #

Discrete (f a) => Discrete (Alt f a) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: Alt f a -> Maybe (Alt f a) Source #

pred :: Alt f a -> Maybe (Alt f a) Source #

a ~ b => Discrete (a :~: b) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: (a :~: b) -> Maybe (a :~: b) Source #

pred :: (a :~: b) -> Maybe (a :~: b) Source #

a ~~ b => Discrete (a :~~: b) Source # 
Instance details

Defined in Data.Discrete

Methods

succ :: (a :~~: b) -> Maybe (a :~~: b) Source #

pred :: (a :~~: b) -> Maybe (a :~~: b) Source #