deferred-folds-0.9.17: Abstractions over deferred folds

DeferredFolds.Prelude

Synopsis

# Documentation

(++) :: [a] -> [a] -> [a] infixr 5 Source #

Append two lists, i.e.,

[x1, ..., xm] ++ [y1, ..., yn] == [x1, ..., xm, y1, ..., yn]
[x1, ..., xm] ++ [y1, ...] == [x1, ..., xm, y1, ...]

If the first list is not finite, the result is the first list.

seq :: forall (r :: RuntimeRep) a (b :: TYPE r). a -> b -> b infixr 0 Source #

The value of seq a b is bottom if a is bottom, and otherwise equal to b. In other words, it evaluates the first argument a to weak head normal form (WHNF). seq is usually introduced to improve performance by avoiding unneeded laziness.

A note on evaluation order: the expression seq a b does not guarantee that a will be evaluated before b. The only guarantee given by seq is that the both a and b will be evaluated before seq returns a value. In particular, this means that b may be evaluated before a. If you need to guarantee a specific order of evaluation, you must use the function pseq from the "parallel" package.

filter :: (a -> Bool) -> [a] -> [a] Source #

$$\mathcal{O}(n)$$. filter, applied to a predicate and a list, returns the list of those elements that satisfy the predicate; i.e.,

filter p xs = [ x | x <- xs, p x]
>>> filter odd [1, 2, 3]
[1,3]


zip :: [a] -> [b] -> [(a, b)] Source #

$$\mathcal{O}(\min(m,n))$$. zip takes two lists and returns a list of corresponding pairs.

zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')]

If one input list is short, excess elements of the longer list are discarded:

zip [1] ['a', 'b'] = [(1, 'a')]
zip [1, 2] ['a'] = [(1, 'a')]

zip is right-lazy:

zip [] _|_ = []
zip _|_ [] = _|_

zip is capable of list fusion, but it is restricted to its first list argument and its resulting list.

newStablePtr :: a -> IO (StablePtr a) Source #

Create a stable pointer referring to the given Haskell value.

print :: Show a => a -> IO () Source #

The print function outputs a value of any printable type to the standard output device. Printable types are those that are instances of class Show; print converts values to strings for output using the show operation and adds a newline.

For example, a program to print the first 20 integers and their powers of 2 could be written as:

main = print ([(n, 2^n) | n <- [0..19]])

fst :: (a, b) -> a Source #

Extract the first component of a pair.

snd :: (a, b) -> b Source #

Extract the second component of a pair.

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
| otherwise = ...

assert :: Bool -> a -> a Source #

If the first argument evaluates to True, then the result is the second argument. Otherwise an AssertionFailed exception is raised, containing a String with the source file and line number of the call to assert.

Assertions can normally be turned on or off with a compiler flag (for GHC, assertions are normally on unless optimisation is turned on with -O or the -fignore-asserts option is given). When assertions are turned off, the first argument to assert is ignored, and the second argument is returned as the result.

lazy :: a -> a Source #

The lazy function restrains strictness analysis a little. The call lazy e means the same as e, but lazy has a magical property so far as strictness analysis is concerned: it is lazy in its first argument, even though its semantics is strict. After strictness analysis has run, calls to lazy are inlined to be the identity function.

This behaviour is occasionally useful when controlling evaluation order. Notably, lazy is used in the library definition of par:

par :: a -> b -> b
par x y = case (par# x) of _ -> lazy y

If lazy were not lazy, par would look strict in y which would defeat the whole purpose of par.

Like seq, the argument of lazy can have an unboxed type.

assertError :: (?callStack :: CallStack) => Bool -> a -> a Source #

trace :: String -> a -> a Source #

The trace function outputs the trace message given as its first argument, before returning the second argument as its result.

For example, this returns the value of f x but first outputs the message.

>>> let x = 123; f = show
>>> trace ("calling f with x = " ++ show x) (f x)
"calling f with x = 123
123"


The trace function should only be used for debugging, or for monitoring execution. The function is not referentially transparent: its type indicates that it is a pure function but it has the side effect of outputting the trace message.

inline :: a -> a Source #

The call inline f arranges that f is inlined, regardless of its size. More precisely, the call inline f rewrites to the right-hand side of f's definition. This allows the programmer to control inlining from a particular call site rather than the definition site of the function (c.f. INLINE pragmas).

This inlining occurs regardless of the argument to the call or the size of f's definition; it is unconditional. The main caveat is that f's definition must be visible to the compiler; it is therefore recommended to mark the function with an INLINABLE pragma at its definition so that GHC guarantees to record its unfolding regardless of size.

If no inlining takes place, the inline function expands to the identity function in Phase zero, so its use imposes no overhead.

map :: (a -> b) -> [a] -> [b] Source #

$$\mathcal{O}(n)$$. map f xs is the list obtained by applying f to each element of xs, i.e.,

map f [x1, x2, ..., xn] == [f x1, f x2, ..., f xn]
map f [x1, x2, ...] == [f x1, f x2, ...]
>>> map (+1) [1, 2, 3]


groupWith :: Ord b => (a -> b) -> [a] -> [[a]] Source #

The groupWith function uses the user supplied function which projects an element out of every list element in order to first sort the input list and then to form groups by equality on these projected elements

($) :: forall (r :: RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b infixr 0 Source # Application operator. This operator is redundant, since ordinary application (f x) means the same as (f$ x). However, $ has low, right-associative binding precedence, so it sometimes allows parentheses to be omitted; for example: f$ g $h x = f (g (h x)) It is also useful in higher-order situations, such as map ($ 0) xs, or zipWith ($) fs xs. Note that ($) is levity-polymorphic in its result type, so that foo \$ True where foo :: Bool -> Int# is well-typed.

coerce :: forall (k :: RuntimeRep) (a :: TYPE k) (b :: TYPE k). Coercible a b => a -> b Source #

The function coerce allows you to safely convert between values of types that have the same representation with no run-time overhead. In the simplest case you can use it instead of a newtype constructor, to go from the newtype's concrete type to the abstract type. But it also works in more complicated settings, e.g. converting a list of newtypes to a list of concrete types.

This function is runtime-representation polymorphic, but the RuntimeRep type argument is marked as Inferred, meaning that it is not available for visible type application. This means the typechecker will accept coerce @Int @Age 42.

fromIntegral :: (Integral a, Num b) => a -> b Source #

general coercion from integral types

realToFrac :: (Real a, Fractional b) => a -> b Source #

general coercion to fractional types

guard :: Alternative f => Bool -> f () Source #

Conditional failure of Alternative computations. Defined by

guard True  = pure ()
guard False = empty


#### Examples

Expand

Common uses of guard include conditionally signaling an error in an error monad and conditionally rejecting the current choice in an Alternative-based parser.

As an example of signaling an error in the error monad Maybe, consider a safe division function safeDiv x y that returns Nothing when the denominator y is zero and Just (x div y) otherwise. For example:

>>> safeDiv 4 0
Nothing
>>> safeDiv 4 2
Just 2


A definition of safeDiv using guards, but not guard:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0    = Just (x div y)
| otherwise = Nothing


A definition of safeDiv using guard and Monad do-notation:

safeDiv :: Int -> Int -> Maybe Int
safeDiv x y = do
guard (y /= 0)
return (x div y)


class IsList l where Source #

The IsList class and its methods are intended to be used in conjunction with the OverloadedLists extension.

Since: base-4.7.0.0

Minimal complete definition

Associated Types

type Item l Source #

The Item type function returns the type of items of the structure l.

Methods

fromList :: [Item l] -> l Source #

The fromList function constructs the structure l from the given list of Item l

fromListN :: Int -> [Item l] -> l Source #

The fromListN function takes the input list's length as a hint. Its behaviour should be equivalent to fromList. The hint can be used to construct the structure l more efficiently compared to fromList. If the given hint does not equal to the input list's length the behaviour of fromListN is not specified.

toList :: l -> [Item l] Source #

The toList function extracts a list of Item l from the structure l. It should satisfy fromList . toList = id.

#### Instances

Instances details
 Be aware that 'fromList . toList = id' only for unfrozen CallStacks, since toList removes frozenness information.Since: base-4.9.0.0 Instance detailsDefined in GHC.Exts Associated Types Methods Since: base-4.8.0.0 Instance detailsDefined in GHC.Exts Associated Types MethodsfromListN :: Int -> [Item Version] -> Version Source # Since: bytestring-0.10.12.0 Instance detailsDefined in Data.ByteString.Short.Internal Associated Types Methods Since: bytestring-0.10.12.0 Instance detailsDefined in Data.ByteString.Lazy.Internal Associated Types Methods Since: bytestring-0.10.12.0 Instance detailsDefined in Data.ByteString.Internal Associated Types Methods Since: containers-0.5.6.2 Instance detailsDefined in Data.IntSet.Internal Associated Types MethodsfromList :: [Item IntSet] -> IntSet Source #fromListN :: Int -> [Item IntSet] -> IntSet Source # Since: primitive-0.6.3.0 Instance detailsDefined in Data.Primitive.ByteArray Associated Types Methods IsList [a] Since: base-4.7.0.0 Instance detailsDefined in GHC.Exts Associated Typestype Item [a] Source # MethodsfromList :: [Item [a]] -> [a] Source #fromListN :: Int -> [Item [a]] -> [a] Source #toList :: [a] -> [Item [a]] Source # Since: base-4.15.0.0 Instance detailsDefined in GHC.Exts Associated Typestype Item (ZipList a) Source # MethodsfromList :: [Item (ZipList a)] -> ZipList a Source #fromListN :: Int -> [Item (ZipList a)] -> ZipList a Source #toList :: ZipList a -> [Item (ZipList a)] Source # Since: base-4.9.0.0 Instance detailsDefined in GHC.Exts Associated Typestype Item (NonEmpty a) Source # MethodsfromList :: [Item (NonEmpty a)] -> NonEmpty a Source #fromListN :: Int -> [Item (NonEmpty a)] -> NonEmpty a Source #toList :: NonEmpty a -> [Item (NonEmpty a)] Source # IsList (IntMap a) Since: containers-0.5.6.2 Instance detailsDefined in Data.IntMap.Internal Associated Typestype Item (IntMap a) Source # MethodsfromList :: [Item (IntMap a)] -> IntMap a Source #fromListN :: Int -> [Item (IntMap a)] -> IntMap a Source #toList :: IntMap a -> [Item (IntMap a)] Source # IsList (Seq a) Instance detailsDefined in Data.Sequence.Internal Associated Typestype Item (Seq a) Source # MethodsfromList :: [Item (Seq a)] -> Seq a Source #fromListN :: Int -> [Item (Seq a)] -> Seq a Source #toList :: Seq a -> [Item (Seq a)] Source # Ord a => IsList (Set a) Since: containers-0.5.6.2 Instance detailsDefined in Data.Set.Internal Associated Typestype Item (Set a) Source # MethodsfromList :: [Item (Set a)] -> Set a Source #fromListN :: Int -> [Item (Set a)] -> Set a Source #toList :: Set a -> [Item (Set a)] Source # Prim a => IsList (PrimArray a) Since: primitive-0.6.4.0 Instance detailsDefined in Data.Primitive.PrimArray Associated Typestype Item (PrimArray a) Source # MethodsfromList :: [Item (PrimArray a)] -> PrimArray a Source #fromListN :: Int -> [Item (PrimArray a)] -> PrimArray a Source #toList :: PrimArray a -> [Item (PrimArray a)] Source # Instance detailsDefined in Data.Primitive.SmallArray Associated Typestype Item (SmallArray a) Source # MethodsfromList :: [Item (SmallArray a)] -> SmallArray a Source #fromListN :: Int -> [Item (SmallArray a)] -> SmallArray a Source #toList :: SmallArray a -> [Item (SmallArray a)] Source # IsList (Array a) Instance detailsDefined in Data.Primitive.Array Associated Typestype Item (Array a) Source # MethodsfromList :: [Item (Array a)] -> Array a Source #fromListN :: Int -> [Item (Array a)] -> Array a Source #toList :: Array a -> [Item (Array a)] Source # (Eq a, Hashable a) => IsList (HashSet a) Instance detailsDefined in Data.HashSet.Internal Associated Typestype Item (HashSet a) Source # MethodsfromList :: [Item (HashSet a)] -> HashSet a Source #fromListN :: Int -> [Item (HashSet a)] -> HashSet a Source #toList :: HashSet a -> [Item (HashSet a)] Source # Source # Instance detailsDefined in DeferredFolds.Defs.Unfoldr Associated Typestype Item (Unfoldr a) Source # MethodsfromList :: [Item (Unfoldr a)] -> Unfoldr a Source #fromListN :: Int -> [Item (Unfoldr a)] -> Unfoldr a Source #toList :: Unfoldr a -> [Item (Unfoldr a)] Source # Source # Instance detailsDefined in DeferredFolds.Defs.Unfoldl Associated Typestype Item (Unfoldl a) Source # MethodsfromList :: [Item (Unfoldl a)] -> Unfoldl a Source #fromListN :: Int -> [Item (Unfoldl a)] -> Unfoldl a Source #toList :: Unfoldl a -> [Item (Unfoldl a)] Source # Ord k => IsList (Map k v) Since: containers-0.5.6.2 Instance detailsDefined in Data.Map.Internal Associated Typestype Item (Map k v) Source # MethodsfromList :: [Item (Map k v)] -> Map k v Source #fromListN :: Int -> [Item (Map k v)] -> Map k v Source #toList :: Map k v -> [Item (Map k v)] Source # (Eq k, Hashable k) => IsList (HashMap k v) Instance detailsDefined in Data.HashMap.Internal Associated Typestype Item (HashMap k v) Source # MethodsfromList :: [Item (HashMap k v)] -> HashMap k v Source #fromListN :: Int -> [Item (HashMap k v)] -> HashMap k v Source #toList :: HashMap k v -> [Item (HashMap k v)] Source # Source # Instance detailsDefined in DeferredFolds.Defs.UnfoldlM Associated Typestype Item (UnfoldlM Identity a) Source # MethodsfromListN :: Int -> [Item (UnfoldlM Identity a)] -> UnfoldlM Identity a Source #

toDyn :: Typeable a => a -> Dynamic Source #

Converts an arbitrary value into an object of type Dynamic.

The type of the object must be an instance of Typeable, which ensures that only monomorphically-typed objects may be converted to Dynamic. To convert a polymorphic object into Dynamic, give it a monomorphic type signature. For example:

   toDyn (id :: Int -> Int)

join :: Monad m => m (m a) -> m a Source #

The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level.

'join bss' can be understood as the do expression

do bs <- bss
bs


#### Examples

Expand

A common use of join is to run an IO computation returned from an STM transaction, since STM transactions can't perform IO directly. Recall that

atomically :: STM a -> IO a


is used to run STM transactions atomically. So, by specializing the types of atomically and join to

atomically :: STM (IO b) -> IO (IO b)
join       :: IO (IO b)  -> IO b


we can compose them as

join . atomically :: STM (IO b) -> IO b


to run an STM transaction and the IO action it returns.

class Bounded a where Source #

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.

Methods

minBound :: a Source #

maxBound :: a Source #

#### Instances

Instances details
 Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Int Methods Since: base-2.1 Instance detailsDefined in GHC.Int Methods Since: base-2.1 Instance detailsDefined in GHC.Int Methods Since: base-2.1 Instance detailsDefined in GHC.Int Methods Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Word Methods Since: base-2.1 Instance detailsDefined in GHC.Word Methods Since: base-2.1 Instance detailsDefined in GHC.Word Methods Since: base-2.1 Instance detailsDefined in GHC.Word Methods Since: base-4.10.0.0 Instance detailsDefined in GHC.Enum Methods Since: base-4.10.0.0 Instance detailsDefined in GHC.Enum Methods Bounded () Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: () Source #maxBound :: () Source # Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Since: base-2.1 Instance detailsDefined in Data.Semigroup.Internal Methods Since: base-2.1 Instance detailsDefined in Data.Semigroup.Internal Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.Ptr Methods Instance detailsDefined in Foreign.Ptr Methods Since: base-2.1 Instance detailsDefined in GHC.Unicode Methods Instance detailsDefined in GHC.LanguageExtensions.Type Methods Bounded a => Bounded (Min a) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods Bounded a => Bounded (Max a) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods Bounded a => Bounded (First a) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods Bounded a => Bounded (Last a) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods Bounded m => Bounded (WrappedMonoid m) Since: base-4.9.0.0 Instance detailsDefined in Data.Semigroup Methods Bounded a => Bounded (Identity a) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methods Bounded a => Bounded (Dual a) Since: base-2.1 Instance detailsDefined in Data.Semigroup.Internal Methods Bounded a => Bounded (Sum a) Since: base-2.1 Instance detailsDefined in Data.Semigroup.Internal Methods Bounded a => Bounded (Product a) Since: base-2.1 Instance detailsDefined in Data.Semigroup.Internal Methods Bounded a => Bounded (Down a) Since: base-4.14.0.0 Instance detailsDefined in Data.Ord Methods (Bounded a, Bounded b) => Bounded (a, b) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b) Source #maxBound :: (a, b) Source # Bounded (Proxy t) Since: base-4.7.0.0 Instance detailsDefined in Data.Proxy Methods (Bounded a, Bounded b, Bounded c) => Bounded (a, b, c) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c) Source #maxBound :: (a, b, c) Source # Bounded a => Bounded (Const a b) Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Const MethodsminBound :: Const a b Source #maxBound :: Const a b Source # (Applicative f, Bounded a) => Bounded (Ap f a) Since: base-4.12.0.0 Instance detailsDefined in Data.Monoid MethodsminBound :: Ap f a Source #maxBound :: Ap f a Source # a ~ b => Bounded (a :~: b) Since: base-4.7.0.0 Instance detailsDefined in Data.Type.Equality MethodsminBound :: a :~: b Source #maxBound :: a :~: b Source # Bounded b => Bounded (Tagged s b) Instance detailsDefined in Data.Tagged Methods (Bounded a, Bounded b, Bounded c, Bounded d) => Bounded (a, b, c, d) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d) Source #maxBound :: (a, b, c, d) Source # a ~~ b => Bounded (a :~~: b) Since: base-4.10.0.0 Instance detailsDefined in Data.Type.Equality MethodsminBound :: a :~~: b Source #maxBound :: a :~~: b Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e) => Bounded (a, b, c, d, e) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e) Source #maxBound :: (a, b, c, d, e) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f) => Bounded (a, b, c, d, e, f) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f) Source #maxBound :: (a, b, c, d, e, f) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g) => Bounded (a, b, c, d, e, f, g) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g) Source #maxBound :: (a, b, c, d, e, f, g) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h) => Bounded (a, b, c, d, e, f, g, h) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h) Source #maxBound :: (a, b, c, d, e, f, g, h) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i) => Bounded (a, b, c, d, e, f, g, h, i) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i) Source #maxBound :: (a, b, c, d, e, f, g, h, i) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j) => Bounded (a, b, c, d, e, f, g, h, i, j) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k) => Bounded (a, b, c, d, e, f, g, h, i, j, k) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j, k) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j, k) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j, k, l) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j, k, l) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # (Bounded a, Bounded b, Bounded c, Bounded d, Bounded e, Bounded f, Bounded g, Bounded h, Bounded i, Bounded j, Bounded k, Bounded l, Bounded m, Bounded n, Bounded o) => Bounded (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsminBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #maxBound :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #

class Enum a where Source #

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 succ maxBound and pred minBound should result in a runtime error.
• fromEnum and toEnum should give a runtime error if the result value is not representable in the result type. For example, toEnum 7 :: Bool is an error.
• enumFrom and enumFromThen should be defined with an implicit bound, thus:
   enumFrom     x   = enumFromTo     x maxBound
enumFromThen x y = enumFromThenTo x y bound
where
| otherwise                = minBound

Minimal complete definition

Methods

succ :: a -> a Source #

the successor of a value. For numeric types, succ adds 1.

pred :: a -> a Source #

the predecessor of a value. For numeric types, pred subtracts 1.

toEnum :: Int -> a Source #

Convert from an Int.

fromEnum :: a -> Int Source #

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.

enumFrom :: a -> [a] Source #

Used in Haskell's translation of [n..] with [n..] = enumFrom n, a possible implementation being enumFrom n = n : enumFrom (succ n). For example:

• enumFrom 4 :: [Integer] = [4,5,6,7,...]
• enumFrom 6 :: [Int] = [6,7,8,9,...,maxBound :: Int]

enumFromThen :: a -> a -> [a] Source #

Used in Haskell's translation of [n,n'..] with [n,n'..] = enumFromThen n n', a possible implementation being enumFromThen n n' = n : n' : worker (f x) (f x n'), worker s v = v : worker s (s v), x = fromEnum n' - fromEnum n and f n y | n > 0 = f (n - 1) (succ y) | n < 0 = f (n + 1) (pred y) | otherwise = y For example:

• enumFromThen 4 6 :: [Integer] = [4,6,8,10...]
• enumFromThen 6 2 :: [Int] = [6,2,-2,-6,...,minBound :: Int]

enumFromTo :: a -> a -> [a] Source #

Used in Haskell's translation of [n..m] with [n..m] = enumFromTo n m, a possible implementation being enumFromTo n m | n <= m = n : enumFromTo (succ n) m | otherwise = []. For example:

• enumFromTo 6 10 :: [Int] = [6,7,8,9,10]
• enumFromTo 42 1 :: [Integer] = []

enumFromThenTo :: a -> a -> a -> [a] Source #

Used in Haskell's translation of [n,n'..m] with [n,n'..m] = enumFromThenTo n n' m, a possible implementation being enumFromThenTo n n' m = worker (f x) (c x) n m, x = fromEnum n' - fromEnum n, c x = bool (>=) ((x 0) f n y | n > 0 = f (n - 1) (succ y) | n < 0 = f (n + 1) (pred y) | otherwise = y and worker s c v m | c v m = v : worker s c (s v) m | otherwise = [] For example:

• enumFromThenTo 4 2 -6 :: [Integer] = [4,2,0,-2,-4,-6]
• enumFromThenTo 6 8 2 :: [Int] = []

#### Instances

Instances details
 Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsenumFrom :: Bool -> [Bool] Source #enumFromThen :: Bool -> Bool -> [Bool] Source #enumFromTo :: Bool -> Bool -> [Bool] Source #enumFromThenTo :: Bool -> Bool -> Bool -> [Bool] Source # Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsenumFrom :: Char -> [Char] Source #enumFromThen :: Char -> Char -> [Char] Source #enumFromTo :: Char -> Char -> [Char] Source #enumFromThenTo :: Char -> Char -> Char -> [Char] Source # Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsenumFrom :: Int -> [Int] Source #enumFromThen :: Int -> Int -> [Int] Source #enumFromTo :: Int -> Int -> [Int] Source #enumFromThenTo :: Int -> Int -> Int -> [Int] Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsenumFrom :: Int8 -> [Int8] Source #enumFromThen :: Int8 -> Int8 -> [Int8] Source #enumFromTo :: Int8 -> Int8 -> [Int8] Source #enumFromThenTo :: Int8 -> Int8 -> Int8 -> [Int8] Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsenumFrom :: Int16 -> [Int16] Source #enumFromThen :: Int16 -> Int16 -> [Int16] Source #enumFromTo :: Int16 -> Int16 -> [Int16] Source #enumFromThenTo :: Int16 -> Int16 -> Int16 -> [Int16] Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsenumFrom :: Int32 -> [Int32] Source #enumFromThen :: Int32 -> Int32 -> [Int32] Source #enumFromTo :: Int32 -> Int32 -> [Int32] Source #enumFromThenTo :: Int32 -> Int32 -> Int32 -> [Int32] Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsenumFrom :: Int64 -> [Int64] Source #enumFromThen :: Int64 -> Int64 -> [Int64] Source #enumFromTo :: Int64 -> Int64 -> [Int64] Source #enumFromThenTo :: Int64 -> Int64 -> Int64 -> [Int64] Source # Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-4.8.0.0 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Enum Methods Since: base-2.1 Instance detailsDefined in GHC.Enum MethodsenumFrom :: Word -> [Word] Source #enumFromThen :: Word -> Word -> [Word] Source #enumFromTo :: Word -> Word -> [Word] Source #enumFromThenTo :: Word -> Word -> Word -> [Word] Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsenumFrom :: Word8 -> [Word8] Source #enumFromThen :: Word8 -> Word8 -> [Word8] Source #enumFromTo :: Word8 -> Word8 -> [Word8] Source #enumFromThenTo :: Word8 -> Word8 -> Word8 -> [Word8] Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsenumFrom :: Word16 -> [Word16] Source #enumFromTo :: Word16 -> Word16 -> [Word16] Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsenumFrom :: Word32 -> [Word32] Source #enumFromTo :: Word32 -> Word32 -> [Word32] Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsenumFrom :: Word64 -> [Word64] Source #enumFromTo :: Word64 -> Word64 -> [Word64] Source # Since: base-4.10.0.0 Instance detailsDefined in GHC.Enum Methods Since: base-4.10.0.0 Instance detailsDefined in GHC.Enum Methods Enum () Since: base-2.1 Instance detailsDefined in GHC.Enum Methodssucc :: () -> () Source #pred :: () -> () Source #toEnum :: Int -> () Source #fromEnum :: () -> Int Source #enumFrom :: () -> [()] Source #enumFromThen :: () -> () -> [()] Source #enumFromTo :: () -> () -> [()] Source #enumFromThenTo :: () -> () -> () -> [()] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CDev -> [CDev] Source #enumFromThen :: CDev -> CDev -> [CDev] Source #enumFromTo :: CDev -> CDev -> [CDev] Source #enumFromThenTo :: CDev -> CDev -> CDev -> [CDev] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CIno -> [CIno] Source #enumFromThen :: CIno -> CIno -> [CIno] Source #enumFromTo :: CIno -> CIno -> [CIno] Source #enumFromThenTo :: CIno -> CIno -> CIno -> [CIno] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CMode -> [CMode] Source #enumFromThen :: CMode -> CMode -> [CMode] Source #enumFromTo :: CMode -> CMode -> [CMode] Source #enumFromThenTo :: CMode -> CMode -> CMode -> [CMode] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: COff -> [COff] Source #enumFromThen :: COff -> COff -> [COff] Source #enumFromTo :: COff -> COff -> [COff] Source #enumFromThenTo :: COff -> COff -> COff -> [COff] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CPid -> [CPid] Source #enumFromThen :: CPid -> CPid -> [CPid] Source #enumFromTo :: CPid -> CPid -> [CPid] Source #enumFromThenTo :: CPid -> CPid -> CPid -> [CPid] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CSsize -> [CSsize] Source #enumFromTo :: CSsize -> CSsize -> [CSsize] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CGid -> [CGid] Source #enumFromThen :: CGid -> CGid -> [CGid] Source #enumFromTo :: CGid -> CGid -> [CGid] Source #enumFromThenTo :: CGid -> CGid -> CGid -> [CGid] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CNlink -> [CNlink] Source #enumFromTo :: CNlink -> CNlink -> [CNlink] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CUid -> [CUid] Source #enumFromThen :: CUid -> CUid -> [CUid] Source #enumFromTo :: CUid -> CUid -> [CUid] Source #enumFromThenTo :: CUid -> CUid -> CUid -> [CUid] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CCc -> [CCc] Source #enumFromThen :: CCc -> CCc -> [CCc] Source #enumFromTo :: CCc -> CCc -> [CCc] Source #enumFromThenTo :: CCc -> CCc -> CCc -> [CCc] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CSpeed -> [CSpeed] Source #enumFromTo :: CSpeed -> CSpeed -> [CSpeed] Source # Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CRLim -> [CRLim] Source #enumFromThen :: CRLim -> CRLim -> [CRLim] Source #enumFromTo :: CRLim -> CRLim -> [CRLim] Source #enumFromThenTo :: CRLim -> CRLim -> CRLim -> [CRLim] Source # Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CId -> [CId] Source #enumFromThen :: CId -> CId -> [CId] Source #enumFromTo :: CId -> CId -> [CId] Source #enumFromThenTo :: CId -> CId -> CId -> [CId] Source # Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CKey -> [CKey] Source #enumFromThen :: CKey -> CKey -> [CKey] Source #enumFromTo :: CKey -> CKey -> [CKey] Source #enumFromThenTo :: CKey -> CKey -> CKey -> [CKey] Source # Instance detailsDefined in System.Posix.Types Methods Instance detailsDefined in System.Posix.Types MethodsenumFrom :: CNfds -> [CNfds] Source #enumFromThen :: CNfds -> CNfds -> [CNfds] Source #enumFromTo :: CNfds -> CNfds -> [CNfds] Source #enumFromThenTo :: CNfds -> CNfds -> CNfds -> [CNfds] Source # Instance detailsDefined in System.Posix.Types Methodssucc :: Fd -> Fd Source #pred :: Fd -> Fd Source #enumFrom :: Fd -> [Fd] Source #enumFromThen :: Fd -> Fd -> [Fd] Source #enumFromTo :: Fd -> Fd -> [Fd] Source #enumFromThenTo :: Fd -> Fd -> Fd -> [Fd] Source # Since: base-4.2.0.0 Instance detailsDefined in GHC.IO.Device Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Since: base-4.9.0.0 Instance detailsDefined in GHC.Generics Methods Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CChar -> [CChar] Source #enumFromThen :: CChar -> CChar -> [CChar] Source #enumFromTo :: CChar -> CChar -> [CChar] Source #enumFromThenTo :: CChar -> CChar -> CChar -> [CChar] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CSChar -> [CSChar] Source #enumFromTo :: CSChar -> CSChar -> [CSChar] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CUChar -> [CUChar] Source #enumFromTo :: CUChar -> CUChar -> [CUChar] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CShort -> [CShort] Source #enumFromTo :: CShort -> CShort -> [CShort] Source # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CInt -> [CInt] Source #enumFromThen :: CInt -> CInt -> [CInt] Source #enumFromTo :: CInt -> CInt -> [CInt] Source #enumFromThenTo :: CInt -> CInt -> CInt -> [CInt] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CUInt -> [CUInt] Source #enumFromThen :: CUInt -> CUInt -> [CUInt] Source #enumFromTo :: CUInt -> CUInt -> [CUInt] Source #enumFromThenTo :: CUInt -> CUInt -> CUInt -> [CUInt] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CLong -> [CLong] Source #enumFromThen :: CLong -> CLong -> [CLong] Source #enumFromTo :: CLong -> CLong -> [CLong] Source #enumFromThenTo :: CLong -> CLong -> CLong -> [CLong] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CULong -> [CULong] Source #enumFromTo :: CULong -> CULong -> [CULong] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CLLong -> [CLLong] Source #enumFromTo :: CLLong -> CLLong -> [CLLong] Source # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CBool -> [CBool] Source #enumFromThen :: CBool -> CBool -> [CBool] Source #enumFromTo :: CBool -> CBool -> [CBool] Source #enumFromThenTo :: CBool -> CBool -> CBool -> [CBool] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CFloat -> [CFloat] Source #enumFromTo :: CFloat -> CFloat -> [CFloat] Source # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CSize -> [CSize] Source #enumFromThen :: CSize -> CSize -> [CSize] Source #enumFromTo :: CSize -> CSize -> [CSize] Source #enumFromThenTo :: CSize -> CSize -> CSize -> [CSize] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CWchar -> [CWchar] Source #enumFromTo :: CWchar -> CWchar -> [CWchar] Source # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CClock -> [CClock] Source #enumFromTo :: CClock -> CClock -> [CClock] Source # Instance detailsDefined in Foreign.C.Types MethodsenumFrom :: CTime -> [CTime] Source #enumFromThen :: CTime -> CTime -> [CTime] Source #enumFromTo :: CTime -> CTime -> [CTime] Source #enumFromThenTo :: CTime -> CTime -> CTime -> [CTime] Source # Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.C.Types Methods Instance detailsDefined in Foreign.Ptr Methods Instance detailsDefined in Foreign.Ptr MethodsenumFrom :: IntPtr -> [IntPtr] Source #enumFromTo :: IntPtr -> IntPtr -> [IntPtr] Source # Since: base-4.2.0.0 Instance detailsDefined in GHC.IO.IOMode MethodsenumFrom :: IOMode -> [IOMode] Source #enumFromTo :: IOMode -> IOMode -> [IOMode] Source # Since: base-2.1 Instance detailsDefined in GHC.Unicode Methods Instance detailsDefined in GHC.LanguageExtensions.Type Methods Integral a => Enum (Ratio a) Since: base-2.0.1 Instance detailsDefined in GHC.Real Methodssucc :: Ratio a -> Ratio a Source #pred :: Ratio a -> Ratio a Source #fromEnum :: Ratio a -> Int Source #enumFrom :: Ratio a -> [Ratio a]