Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Discrete a where
Documentation
class Discrete a where Source #
A Discrete
type is a set X with at least one element, along with two
functions,
and succ
:: 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
:: X -> Maybe
X
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
thenNothing
elseJust
(x+
1)
pred
x = if x==
minBound
thenNothing
elseJust
(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
.
Instances
Discrete Bool Source # | |
Discrete Char Source # | |
Discrete Int Source # | |
Discrete Int8 Source # | |
Discrete Int16 Source # | |
Discrete Int32 Source # | |
Discrete Int64 Source # | |
Discrete Integer Source # | |
Discrete Ordering Source # | |
Discrete Word Source # | |
Discrete Word8 Source # | |
Discrete Word16 Source # | |
Discrete Word32 Source # | |
Discrete Word64 Source # | |
Discrete () Source # | |
Discrete a => Discrete (Maybe a) Source # | |
Integral a => Discrete (Ratio a) Source # | |
Discrete a => Discrete (Identity a) Source # | |
(Bounded a, Bounded b, Discrete a, Discrete b) => Discrete (Either a b) Source # | |
(Bounded b, Discrete a, Discrete b) => Discrete (a, b) Source # | |
Discrete a => Discrete (Const a b) Source # | |
Discrete (f a) => Discrete (Alt f a) Source # | |
a ~ b => Discrete (a :~: b) Source # | |
a ~~ b => Discrete (a :~~: b) Source # | |