| Copyright | (c) Ross Paterson 2002 |
|---|---|
| License | BSD-style (see the LICENSE file in the distribution) |
| Maintainer | libraries@haskell.org |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Control.Arrow
Contents
Description
Basic arrow definitions, based on
plus a couple of definitions (returnA andloop) from
These papers and more information on arrows can be found athttp://www.haskell.org/arrows/.
classCategory a =>Arrow awhereSource#
The basic arrow class.
Instances should satisfy the following laws:
arrid =id
arr(f >>> g) =arrf >>>arrg
first(arrf) =arr(firstf)
first(f >>> g) =firstf >>>firstg
firstf >>>arrfst=arrfst>>> f
firstf >>>arr(id*** g) =arr(id*** g) >>>firstf
first(firstf) >>>arrassoc=arrassoc>>>firstf
where
assoc ((a,b),c) = (a,(b,c))
The other combinators have sensible default definitions, which may be overridden for efficiency.
Methods
arr :: (b -> c) -> a b cSource#
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 offirst.
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 3Source#
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 3Source#
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.
Constructors
| Kleisli | |
Fields
| |
| MonadFix m =>ArrowLoop (Kleisli m)Source# | Beware that for many monads (those for which the Since: 2.1 |
| Monad m =>ArrowApply (Kleisli m)Source# | Since: 2.1 |
| Monad m =>ArrowChoice (Kleisli m)Source# | Since: 2.1 |
Instance detailsDefined inControl.Arrow | |
| MonadPlus m =>ArrowPlus (Kleisli m)Source# | Since: 2.1 |
| MonadPlus m =>ArrowZero (Kleisli m)Source# | Since: 2.1 |
| Monad m =>Arrow (Kleisli m)Source# | Since: 2.1 |
Instance detailsDefined inControl.Arrow | |
| Monad m =>Category (Kleisli m ::Type ->Type ->Type)Source# | Since: 3.0 |
returnA ::Arrow a => a b bSource#
The identity arrow, which plays the role ofreturn in arrow notation.
(<<^) ::Arrow a => a c d -> (b -> c) -> a b dinfixr 1Source#
Precomposition with a pure function (right-to-left variant).
(^<<) ::Arrow a => (c -> d) -> a b c -> a b dinfixr 1Source#
Postcomposition with a pure function (right-to-left variant).
classArrowZero a =>ArrowPlus awhereSource#
A monoid on arrows.
classArrow a =>ArrowChoice awhereSource#
Choice, for arrows that support it. This class underlies theif andcase constructs in arrow notation.
Instances should satisfy the following laws:
left(arrf) =arr(leftf)
left(f >>> g) =leftf >>>leftg
f >>>arrLeft=arrLeft>>>leftf
leftf >>>arr(id+++ g) =arr(id+++ g) >>>leftf
left(leftf) >>>arrassocsum=arrassocsum>>>leftf
where
assocsum (Left (Left x)) = Left xassocsum (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.
Methods
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 ofleft.
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 2Source#
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) dinfixr 2Source#
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.
| Monad m =>ArrowChoice (Kleisli m)Source# | Since: 2.1 |
Instance detailsDefined inControl.Arrow | |
| ArrowChoice ((->) ::Type ->Type ->Type)Source# | Since: 2.1 |
classArrow a =>ArrowApply awhereSource#
newtypeArrowMonad a bSource#
TheArrowApply class is equivalent toMonad: any monad gives rise to aKleisli arrow, and any instance ofArrowApply defines a monad.
Constructors
| ArrowMonad (a () b) |
leftApp ::ArrowApply a => a b c -> a (Either b d) (Either c d)Source#
Any instance ofArrowApply can be made into an instance ofArrowChoice by definingleft =leftApp.
classArrow a =>ArrowLoop awhereSource#
Theloop operator expresses computations in which an output value is fed back as input, although the computation occurs only once. It underlies therec 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 floop (f >>>first h) =loop f >>> hloop (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)
Produced byHaddock version 2.20.0