Copyright | (c) Ross Paterson 2002 |
---|---|
License | BSD-style (see the LICENSE file in the distribution) |
Maintainer | [email protected] |
Stability | provisional |
Portability | portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Basic arrow definitions, based on
plus a couple of definitions (returnA
and loop
) from
These papers and more information on arrows can be found at http://www.haskell.org/arrows/.
class Category a => Arrow a where Source
The basic arrow class.
Instances should satisfy the following laws:
arr
id =id
arr
(f >>> g) =arr
f >>>arr
g
first
(arr
f) =arr
(first
f)
first
(f >>> g) =first
f >>>first
g
first
f >>>arr
fst
=arr
fst
>>> f
first
f >>>arr
(id
*** g) =arr
(id
*** g) >>>first
f
first
(first
f) >>>arr
assoc
=arr
assoc
>>>first
f
where
assoc ((a,b),c) = (a,(b,c))
The other combinators have sensible default definitions, which may be overridden for efficiency.
arr :: (b -> c) -> a b c Source
Lift a function to an arrow.
first :: a b c -> a (b, d) (c, d) Source
Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.
second :: a b c -> a (d, b) (d, c) Source
A mirror image of first
.
The default definition may be overridden with a more efficient version if desired.
(***) :: a b c -> a b' c' -> a (b, b') (c, c') infixr 3 Source
Split the input between the two argument arrows and combine their output. Note that this is in general not a functor.
The default definition may be overridden with a more efficient version if desired.
(&&&) :: a b c -> a b c' -> a b (c, c') infixr 3 Source
Fanout: send the input to both argument arrows and combine their output.
The default definition may be overridden with a more efficient version if desired.
Kleisli arrows of a monad.
Kleisli | |
Fields
|
Monad m => Category * (Kleisli m) | |
MonadFix m => ArrowLoop (Kleisli m) | Beware that for many monads (those for which the |
Monad m => ArrowApply (Kleisli m) | |
Monad m => ArrowChoice (Kleisli m) | |
MonadPlus m => ArrowPlus (Kleisli m) | |
MonadPlus m => ArrowZero (Kleisli m) | |
Monad m => Arrow (Kleisli m) |
returnA :: Arrow a => a b b Source
The identity arrow, which plays the role of return
in arrow notation.
(^>>) :: Arrow a => (b -> c) -> a c d -> a b d infixr 1 Source
Precomposition with a pure function.
(>>^) :: Arrow a => a b c -> (c -> d) -> a b d infixr 1 Source
Postcomposition with a pure function.
(>>>) :: Category cat => cat a b -> cat b c -> cat a c infixr 1 Source
Left-to-right composition
(<<<) :: Category cat => cat b c -> cat a b -> cat a c infixr 1 Source
Right-to-left composition
(<<^) :: Arrow a => a c d -> (b -> c) -> a b d infixr 1 Source
Precomposition with a pure function (right-to-left variant).
(^<<) :: Arrow a => (c -> d) -> a b c -> a b d infixr 1 Source
Postcomposition with a pure function (right-to-left variant).
class Arrow a => ArrowZero a where Source
class ArrowZero a => ArrowPlus a where Source
A monoid on arrows.
(<+>) :: a b c -> a b c -> a b c infixr 5 Source
An associative operation with identity zeroArrow
.
class Arrow a => ArrowChoice a where Source
Choice, for arrows that support it. This class underlies the if
and case
constructs in arrow notation.
Instances should satisfy the following laws:
left
(arr
f) =arr
(left
f)
left
(f >>> g) =left
f >>>left
g
f >>>arr
Left
=arr
Left
>>>left
f
left
f >>>arr
(id
+++ g) =arr
(id
+++ g) >>>left
f
left
(left
f) >>>arr
assocsum
=arr
assocsum
>>>left
f
where
assocsum (Left (Left x)) = Left x assocsum (Left (Right y)) = Right (Left y) assocsum (Right z) = Right (Right z)
The other combinators have sensible default definitions, which may be overridden for efficiency.
left :: a b c -> a (Either b d) (Either c d) Source
Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.
right :: a b c -> a (Either d b) (Either d c) Source
A mirror image of left
.
The default definition may be overridden with a more efficient version if desired.
(+++) :: a b c -> a b' c' -> a (Either b b') (Either c c') infixr 2 Source
Split the input between the two argument arrows, retagging and merging their outputs. Note that this is in general not a functor.
The default definition may be overridden with a more efficient version if desired.
(|||) :: a b d -> a c d -> a (Either b c) d infixr 2 Source
Fanin: Split the input between the two argument arrows and merge their outputs.
The default definition may be overridden with a more efficient version if desired.
ArrowChoice (->) | |
Monad m => ArrowChoice (Kleisli m) |
class Arrow a => ArrowApply a where Source
Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:
first
(arr
(\x ->arr
(\y -> (x,y)))) >>>app
=id
first
(arr
(g >>>)) >>>app
=second
g >>>app
first
(arr
(>>> h)) >>>app
=app
>>> h
Such arrows are equivalent to monads (see ArrowMonad
).
ArrowApply (->) | |
Monad m => ArrowApply (Kleisli m) |
newtype ArrowMonad a b Source
The ArrowApply
class is equivalent to Monad
: any monad gives rise to a Kleisli
arrow, and any instance of ArrowApply
defines a monad.
ArrowMonad (a () b) |
ArrowApply a => Monad (ArrowMonad a) | |
Arrow a => Functor (ArrowMonad a) | |
Arrow a => Applicative (ArrowMonad a) | |
(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | |
ArrowPlus a => Alternative (ArrowMonad a) |
leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) Source
Any instance of ArrowApply
can be made into an instance of ArrowChoice
by defining left
= leftApp
.
class Arrow a => ArrowLoop a where Source
The loop
operator expresses computations in which an output value is fed back as input, although the computation occurs only once. It underlies the rec
value recursion construct in arrow notation. loop
should satisfy the following laws:
loop (arr f) = arr (\ b -> fst (fix (\ (c,d) -> f (b,d))))
loop (first h >>> f) = h >>> loop f
loop (f >>> first h) = loop f >>> h
loop (f >>> arr (id *** k)) = loop (arr (id *** k) >>> f)
loop (loop f) = loop (arr unassoc >>> f >>> arr assoc)
second (loop f) = loop (arr assoc >>> second f >>> arr unassoc)
where
assoc ((a,b),c) = (a,(b,c)) unassoc (a,(b,c)) = ((a,b),c)
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/7.10.3/docs/html/libraries/base-4.8.2.0/Control-Arrow.html