|
Generics.EMGM.Functions.Crush | Portability | non-portable | Stability | experimental | Maintainer | generics@haskell.org |
|
|
|
|
|
Description |
Summary: Generic functions that crush a container into an iteration over
its elements.
Crush is a datatype-generic operation on container types. It is a
generalization of folds, but it is not a catamorphism. To understand how
crush works, one can think of it as generating a list of all elements and
mapping an accumulating function over each one. With this image in mind, it
is evident that (unlike a catamorphism) very little information can be
determined about the structure of the container.
The EMGM implementation of crush can not inherently know the associativity
of the binary operator. Consequently, associativity is left as an argument,
but there are variants specific to left- and right-associativity for
convenience.
Many standard Haskell datatypes (e.g. '[]', Data.Tree) are designed such
that a constructor with more than one argument (i.e. a product structurally
represented by '(:*:)') has the element on the left and any recursive points
towards the right. Due to this, the right-associative functions would
typically produce the expected values. See examples in the comments for
flattenr and firstr.
|
|
Synopsis |
|
|
|
|
Crush functions
|
|
|
Type for crush
| Constructors | Crush | | selCrush :: Assoc -> a -> b -> b | |
|
| Instances | |
|
|
|
Associativity of the binary operator used for crush
| Constructors | AssocLeft | Left-associative
| AssocRight | Right-associative
|
|
|
|
|
:: FRep (Crush b) f | | => Assoc | Associativity of the binary operator (left or right).
| -> a -> b -> b | Binary operator on a-elements with an accumulator.
| -> b | The initial b-value for the binary operator.
| -> f a | Container of a-values.
| -> b | The result after applying the above operator on all
a-values.
| Apply a function (a -> b -> b) to each element (a) of a container (f
a) and an accumulator value (b) to produce an accumulated result (b).
This is the most general form in which you must specify the associativity.
You may prefer to use crushr or crushl.
|
|
|
|
A left-associative variant of crush.
|
|
|
A right-associative variant of crush.
|
|
Left- and right-associative derived functions
|
|
The operation of these functions changes depending on the associativity
of the binary operator.
|
|
|
Flatten the elements of a container into a list.
This is the most general form in which you must specify the associativity.
You may prefer to use flattenr or flattenl.
|
|
|
A left-associative variant of flatten.
Note that, for a list ls :: [a], flattenl ls == reverse ls.
|
|
|
A right-associative variant of flatten.
Note that, for a list ls :: [a], flattenr ls == ls.
|
|
|
Extract the first element of a container. If the container is empty, return
Nothing.
This is the most general form in which you must specify the associativity.
You may prefer to use firstr or firstl.
|
|
|
A left-associative variant of first.
Note that, for a list ls :: [a], fromJust (firstl ls) == last ls.
|
|
|
A right-associative variant of first.
Note that, for a list ls :: [a], fromJust (firstr ls) == head ls.
|
|
Other derived functions
|
|
The operation of these functions is independent of the associativity of
the binary operator. Many of these functions are generalizations of the
Prelude functions of the same name
|
|
|
Compute the conjunction of all elements in a container. This is a
generalization of the Prelude function of the same name.
|
|
|
Compute the disjunction of all elements in a container. This is a
generalization of the Prelude function of the same name.
|
|
|
Determine if any element in a container satisfies the predicate p. This
is a generalization of the Prelude function of the same name.
|
|
|
Determine if all elements in a container satisfy the predicate p. This
is a generalization the Prelude function of the same name.
|
|
|
Compute the sum of all elements in a container. This is a generalization of
the Prelude function of the same name.
|
|
|
Compute the product of all elements in a container. This is a
generalization of the Prelude function of the same name.
|
|
|
Determine the maximum element of a container. If the container is empty,
return Nothing. This is a generalization of the Prelude function of the
same name.
|
|
|
Determine the minimum element of a container. If the container is empty,
return Nothing. This is a generalization of the Prelude function of the
same name.
|
|
|
Determine if an element is a member of a container. This is a
generalization of the Prelude function of the same name.
|
|
|
Determine if an element is not a member of a container. This is a
generalization of the Prelude function of the same name.
|
|
Produced by Haddock version 2.4.2 |