| 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 |
GHC.Internal.Control.Arrow
Description
Basic arrow definitions, based on
- Generalising Monads to Arrows, by John Hughes, Science of Computer Programming 37, pp67-111, May 2000.
plus a couple of definitions (returnA and loop) from
- A New Notation for Arrows, by Ross Paterson, in ICFP 2001, Firenze, Italy, pp229-240.
These papers and more information on arrows can be found at http://www.haskell.org/arrows/.
Synopsis
- class Category a => Arrow (a :: Type -> Type -> Type) where
- newtype Kleisli (m :: Type -> Type) 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
- (>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c
- (<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c
- (<<^) :: 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 :: Type -> Type -> Type) where
- zeroArrow :: a b c
- class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where
- (<+>) :: a b c -> a b c -> a b c
- class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where
- class Arrow a => ArrowApply (a :: Type -> Type -> Type) where
- app :: a (a b c, b) c
- newtype ArrowMonad (a :: Type -> Type -> Type) b = ArrowMonad (a () b)
- leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d)
Arrows
class Category a => Arrow (a :: Type -> Type -> Type) where Source #
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
arr :: (b -> c) -> a b c Source #
Lift a function to an arrow.
b ╭───╮ c
>───┤ f ├───>
╰───╯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.
The default definition may be overridden with a more efficient version if desired.
b ╭─────╮ c >───┼─ f ─┼───> >───┼─────┼───> d ╰─────╯ d
second :: a b c -> a (d, b) (d, c) Source #
Send the second component of the input through the argument arrow, and copy the rest unchanged to the output.
The default definition may be overridden with a more efficient version if desired.
d ╭─────╮ d >───┼─────┼───> >───┼─ f ─┼───> b ╰─────╯ c
(***) :: 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.
b ╭─────╮ c >───┼─ f ─┼───> >───┼─ g ─┼───> b'╰─────╯ c'
(&&&) :: 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.
╭───────╮ c
b │ ┌─ f ─┼───>
>───┼─┤ │
│ └─ g ─┼───>
╰───────╯ c'Instances
| Monad m => Arrow (Kleisli m) Source # | Since: base-2.1 |
Defined in GHC.Internal.Control.Arrow Methods arr :: (b -> c) -> Kleisli m b c Source # first :: Kleisli m b c -> Kleisli m (b, d) (c, d) Source # second :: Kleisli m b c -> Kleisli m (d, b) (d, c) Source # (***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') Source # (&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') Source # | |
newtype Kleisli (m :: Type -> Type) a b Source #
Kleisli arrows of a monad.
Constructors
| Kleisli | |
Fields
| |
Instances
| Monad m => Category (Kleisli m :: Type -> Type -> Type) Source # | Since: base-3.0 | ||||
| Generic1 (Kleisli m a :: Type -> Type) Source # | |||||
Defined in GHC.Internal.Control.Arrow Associated Types
| |||||
| Monad m => Arrow (Kleisli m) Source # | Since: base-2.1 | ||||
Defined in GHC.Internal.Control.Arrow Methods arr :: (b -> c) -> Kleisli m b c Source # first :: Kleisli m b c -> Kleisli m (b, d) (c, d) Source # second :: Kleisli m b c -> Kleisli m (d, b) (d, c) Source # (***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') Source # (&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') Source # | |||||
| Monad m => ArrowApply (Kleisli m) Source # | Since: base-2.1 | ||||
| Monad m => ArrowChoice (Kleisli m) Source # | Since: base-2.1 | ||||
Defined in GHC.Internal.Control.Arrow Methods left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) Source # right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) Source # (+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') Source # (|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d Source # | |||||
| MonadPlus m => ArrowPlus (Kleisli m) Source # | Since: base-2.1 | ||||
| MonadPlus m => ArrowZero (Kleisli m) Source # | Since: base-2.1 | ||||
Defined in GHC.Internal.Control.Arrow | |||||
| MonadFix m => ArrowLoop (Kleisli m) Source # | Beware that for many monads (those for which the Since: base-2.1 | ||||
| Alternative m => Alternative (Kleisli m a) Source # | Since: base-4.14.0.0 | ||||
| Applicative m => Applicative (Kleisli m a) Source # | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Control.Arrow Methods pure :: a0 -> Kleisli m a a0 Source # (<*>) :: Kleisli m a (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b Source # liftA2 :: (a0 -> b -> c) -> Kleisli m a a0 -> Kleisli m a b -> Kleisli m a c Source # (*>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b Source # (<*) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a a0 Source # | |||||
| Functor m => Functor (Kleisli m a) Source # | Since: base-4.14.0.0 | ||||
| Monad m => Monad (Kleisli m a) Source # | Since: base-4.14.0.0 | ||||
| MonadPlus m => MonadPlus (Kleisli m a) Source # | Since: base-4.14.0.0 | ||||
| Generic (Kleisli m a b) Source # | |||||
Defined in GHC.Internal.Control.Arrow Associated Types
| |||||
| type Rep1 (Kleisli m a :: Type -> Type) Source # | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Control.Arrow | |||||
| type Rep (Kleisli m a b) Source # | Since: base-4.14.0.0 | ||||
Defined in GHC.Internal.Control.Arrow | |||||
Derived combinators
returnA :: Arrow a => a b b Source #
The identity arrow, which plays the role of return in arrow notation.
b >───>
(^>>) :: 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.
(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c infixr 1 Source #
Left-to-right composition. This is useful if you want to write a morphism as a pipeline going from left to right.
(<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c infixr 1 Source #
Right-to-left composition. This is a synonym for (.), but it can be useful to make
the order of composition more apparent.
Right-to-left variants
(<<^) :: 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).
Monoid operations
class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where Source #
A monoid on arrows.
Conditionals
class Arrow a => ArrowChoice (a :: Type -> Type -> Type) 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(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) 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.
Instances
| Monad m => ArrowChoice (Kleisli m) Source # | Since: base-2.1 |
Defined in GHC.Internal.Control.Arrow Methods left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) Source # right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) Source # (+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') Source # (|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d Source # | |
Arrow application
class Arrow a => ArrowApply (a :: Type -> Type -> Type) where Source #
newtype ArrowMonad (a :: Type -> Type -> Type) 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.
Constructors
| ArrowMonad (a () b) |
Instances
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.