Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Enum class
Class Enum
defines operations on sequentially ordered types.
The enumFrom
... methods are used in Haskell's translation of
arithmetic sequences.
Instances of Enum
may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum
from 0
through n-1
.
See Chapter 10 of the Haskell Report for more details.
For any type that is an instance of class Bounded
as well as Enum
,
the following should hold:
- The calls
andsucc
maxBound
should result in a runtime error.pred
minBound
fromEnum
andtoEnum
should give a runtime error if the result value is not representable in the result type. For example,
is an error.toEnum
7 ::Bool
enumFrom
andenumFromThen
should be defined with an implicit bound, thus:
enumFrom x = enumFromTo x maxBound enumFromThen x y = enumFromThenTo x y bound where bound | fromEnum y >= fromEnum x = maxBound | otherwise = minBound
the successor of a value. For numeric types, succ
adds 1.
the predecessor of a value. For numeric types, pred
subtracts 1.
Convert from an Int
.
Convert to an Int
.
It is implementation-dependent what fromEnum
returns when
applied to a value that is too large to fit in an Int
.
Used in Haskell's translation of [n..]
.
enumFromThen :: a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
.
enumFromTo :: a -> a -> [a] #
Used in Haskell's translation of [n..m]
.
enumFromThenTo :: a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m]
.
Enum Bool | |
Enum Char | |
Enum Int | |
Enum Int8 | |
Enum Int16 | |
Enum Int32 | |
Enum Int64 | |
Enum Integer | |
Enum Ordering | |
Enum Word | |
Enum Word8 | |
Enum Word16 | |
Enum Word32 | |
Enum Word64 | |
Enum () | |
Enum Associativity | |
Enum SourceUnpackedness | |
Enum SourceStrictness | |
Enum DecidedStrictness | |
Enum Extension | |
Enum GenTextMethods | |
Integral a => Enum (Ratio a) | |
Enum a => Enum (Identity a) | |
Enum a => Enum (Min a) | |
Enum a => Enum (Max a) | |
Enum a => Enum (First a) | |
Enum a => Enum (Last a) | |
Enum a => Enum (WrappedMonoid a) | |
Enum (Proxy k s) | |
Enum a => Enum (Const k a b) | |
Enum (f a) => Enum (Alt k f a) | |
(~) k a b => Enum ((:~:) k a b) | |
Enum a => Enum (Tagged k s a) | |
enumFromThen :: Enum a => a -> a -> [a] #
Used in Haskell's translation of [n,n'..]
.
enumFromTo :: Enum a => a -> a -> [a] #
Used in Haskell's translation of [n..m]
.
enumFromThenTo :: Enum a => a -> a -> a -> [a] #
Used in Haskell's translation of [n,n'..m]
.
Bounded class
The Bounded
class is used to name the upper and lower limits of a
type. Ord
is not a superclass of Bounded
since types that are not
totally ordered may also have upper and lower bounds.
The Bounded
class may be derived for any enumeration type;
minBound
is the first constructor listed in the data
declaration
and maxBound
is the last.
Bounded
may also be derived for single-constructor datatypes whose
constituent types are in Bounded
.