| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Precursor.Control.Category
Contents
- class Category k cat where
- (.) :: Category k cat => forall b c a. cat b c -> cat a b -> cat a c
- id :: Category k cat => forall a. cat a a
- (<<<) :: Category k cat => cat b c -> cat a b -> cat a c
- (>>>) :: Category k cat => cat a b -> cat b c -> cat a c
- class Category * a => Arrow a where
- arr :: Arrow a => forall b c. (b -> c) -> a b c
- (***) :: Arrow a => forall b c b' c'. a b c -> a b' c' -> a (b, b') (c, c')
- (&&&) :: Arrow a => forall b c c'. a b c -> a b c' -> a b (c, c')
- newtype Kleisli m a b :: (* -> *) -> * -> * -> * = Kleisli {
- runKleisli :: a -> m b
- returnA :: Arrow a => a b b
- (^>>) :: Arrow a => (b -> c) -> a c d -> a b d
- (>>^) :: Arrow a => a b c -> (c -> d) -> a b d
- (<<^) :: Arrow a => a c d -> (b -> c) -> a b d
- (^<<) :: Arrow a => (c -> d) -> a b c -> a b d
- class Arrow a => ArrowZero a where
- zeroArrow :: ArrowZero a => forall b c. a b c
- class ArrowZero a => ArrowPlus a where
- (<+>) :: ArrowPlus a => forall b c. a b c -> a b c -> a b c
- class Arrow a => ArrowChoice a where
- left :: ArrowChoice a => forall b c d. a b c -> a (Either b d) (Either c d)
- right :: ArrowChoice a => forall b c d. a b c -> a (Either d b) (Either d c)
- (+++) :: ArrowChoice a => forall b c b' c'. a b c -> a b' c' -> a (Either b b') (Either c c')
- (|||) :: ArrowChoice a => forall b d c. a b d -> a c d -> a (Either b c) d
- class Arrow a => ArrowApply a where
- app :: ArrowApply a => forall b c. a (a b c, b) c
- newtype ArrowMonad a b :: (* -> * -> *) -> * -> * = ArrowMonad (a () b)
- leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d)
- class Arrow a => ArrowLoop a where
- loop :: ArrowLoop a => forall b d c. a (b, d) (c, d) -> a b c
Category
A class for categories. id and (.) must form a monoid.
Composition
Arrow
class Category * a => Arrow a where #
The basic arrow class.
Instances should satisfy the following laws:
arrid =idarr(f >>> g) =arrf >>>arrgfirst(arrf) =arr(firstf)first(f >>> g) =firstf >>>firstgfirstf >>>arrfst=arrfst>>> ffirstf >>>arr(id*** g) =arr(id*** g) >>>firstffirst(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
Lift a function to an arrow.
(***) :: a b c -> a b' c' -> a (b, b') (c, c') infixr 3 #
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 #
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.
(***) :: Arrow a => forall b c b' c'. a b c -> a b' c' -> a (b, b') (c, c') #
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.
(&&&) :: Arrow a => forall b c c'. a b c -> a b c' -> a b (c, c') #
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.
Arrows
newtype Kleisli m a b :: (* -> *) -> * -> * -> * #
Kleisli arrows of a monad.
Constructors
| Kleisli | |
Fields
| |
Instances
| Monad m => Arrow (Kleisli m) | |
| MonadPlus m => ArrowZero (Kleisli m) | |
| MonadPlus m => ArrowPlus (Kleisli m) | |
| Monad m => ArrowChoice (Kleisli m) | |
| Monad m => ArrowApply (Kleisli m) | |
| MonadFix m => ArrowLoop (Kleisli m) | Beware that for many monads (those for which the |
| Monad m => Category * (Kleisli m) | |
Derived combinators
Right-to-left variants
(<<^) :: Arrow a => a c d -> (b -> c) -> a b d infixr 1 #
Precomposition with a pure function (right-to-left variant).
(^<<) :: Arrow a => (c -> d) -> a b c -> a b d infixr 1 #
Postcomposition with a pure function (right-to-left variant).
Monoid operations
(<+>) :: ArrowPlus a => forall b c. a b c -> a b c -> a b c #
An associative operation with identity zeroArrow.
Conditionals
class Arrow a => ArrowChoice a where #
Choice, for arrows that support it. This class underlies the
if and case constructs in arrow notation.
Instances should satisfy the following laws:
left(arrf) =arr(leftf)left(f >>> g) =leftf >>>leftgf >>>
arrLeft=arrLeft>>>leftfleftf >>>arr(id+++ g) =arr(id+++ g) >>>leftfleft(leftf) >>>arrassocsum=arrassocsum>>>leftf
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.
Methods
left :: a b c -> a (Either b d) (Either c d) #
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) #
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 #
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 #
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.
Instances
| ArrowChoice (->) | |
| Monad m => ArrowChoice (Kleisli m) | |
left :: ArrowChoice a => forall b c d. a b c -> a (Either b d) (Either c d) #
Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.
right :: ArrowChoice a => forall b c d. a b c -> a (Either d b) (Either d c) #
A mirror image of left.
The default definition may be overridden with a more efficient version if desired.
(+++) :: ArrowChoice a => forall b c b' c'. a b c -> a b' c' -> a (Either b b') (Either c c') #
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.
(|||) :: ArrowChoice a => forall b d c. a b d -> a c d -> a (Either b c) d #
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.
Arrow application
class Arrow a => ArrowApply a where #
Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:
first(arr(\x ->arr(\y -> (x,y)))) >>>app=idfirst(arr(g >>>)) >>>app=secondg >>>appfirst(arr(>>> h)) >>>app=app>>> h
Such arrows are equivalent to monads (see ArrowMonad).
Minimal complete definition
Instances
| ArrowApply (->) | |
| Monad m => ArrowApply (Kleisli m) | |
app :: ArrowApply a => forall b c. a (a b c, b) c #
newtype ArrowMonad a b :: (* -> * -> *) -> * -> * #
The ArrowApply class is equivalent to Monad: any monad gives rise
to a Kleisli arrow, and any instance of ArrowApply defines a monad.
Constructors
| ArrowMonad (a () b) |
Instances
| ArrowApply a => Monad (ArrowMonad a) | |
| Arrow a => Functor (ArrowMonad a) | |
| Arrow a => Applicative (ArrowMonad a) | |
| ArrowPlus a => Alternative (ArrowMonad a) | |
| (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) | |
leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) #
Any instance of ArrowApply can be made into an instance of
ArrowChoice by defining left = leftApp.
Feedback
class Arrow a => ArrowLoop a where #
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:
- extension
loop(arrf) =arr(\ b ->fst(fix(\ (c,d) -> f (b,d))))- left tightening
loop(firsth >>> f) = h >>>loopf- right tightening
loop(f >>>firsth) =loopf >>> h- sliding
loop(f >>>arr(id*** k)) =loop(arr(id*** k) >>> f)- vanishing
loop(loopf) =loop(arrunassoc >>> f >>>arrassoc)- superposing
second(loopf) =loop(arrassoc >>>secondf >>>arrunassoc)
where
assoc ((a,b),c) = (a,(b,c)) unassoc (a,(b,c)) = ((a,b),c)
Minimal complete definition