class Plus :: (Type -> Type) -> Constraint
class (Alt f) <= Plus f where
Plus type class extends the
Alt type class with a value that
should be the left and right identity for
It is similar to
Monoid, except that it applies to types of
* -> *, like
List, rather than concrete types like
Plus instances should satisfy the following laws:
- Left identity:
empty <|> x == x
- Right identity:
x <|> empty == x
f <$> empty == empty
empty :: forall a. f a
Re-exports from Control.
class Alt :: (Type -> Type) -> Constraint
class (Functor f) <= Alt f where
Alt type class identifies an associative operation on a type
constructor. It is similar to
Semigroup, except that it applies to
types of kind
* -> *, like
List, rather than concrete types
Alt instances are required to satisfy the following laws:
(x <|> y) <|> z == x <|> (y <|> z)
f <$> (x <|> y) == (f <$> x) <|> (f <$> y)
For example, the
) type is an instance of
(<|>) is defined to be concatenation.
A common use case is to select the first "valid" item, or, if all items are "invalid", the last "invalid" item.
import Control.Alt ((<|>)) import Data.Maybe (Maybe(..) import Data.Either (Either(..)) Nothing <|> Just 1 <|> Just 2 == Just 1 Left "err" <|> Right 1 <|> Right 2 == Right 1 Left "err 1" <|> Left "err 2" <|> Left "err 3" == Left "err 3"
alt :: forall a. f a -> f a -> f a
Re-exports from Data.
class Functor :: (Type -> Type) -> Constraint
class Functor f where
Functor is a type constructor which supports a mapping operation
map can be used to turn functions
a -> b into functions
f a -> f b whose argument and return types use the type constructor
to represent some computational context.
Instances must satisfy the following laws:
map identity = identity
map (f <<< g) = map f <<< map g
map :: forall a b. (a -> b) -> f a -> f b
void :: forall f a. Functor f => f a -> f Unit
void function is used to ignore the type wrapped by a
Functor, replacing it with
Unit and keeping only the type
information provided by the type constructor itself.
void is often useful when using
do notation to change the return type
of a monadic computation:
main = forE 1 10 \n -> void do print n print (n * n)