HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Moduleghc-internal-10.0.0Haskell2010

GHC.Internal.Control.Arrow

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/.

  • 2 types
  • 5 classes
  • 8 values

Arrows

2 declarations
classclass Category a => Arrow (a :: Type -> Type -> Type) where
#

The basic arrow class.

Instances should satisfy the following laws:

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

    Lift a function to an arrow.

      b ╭───╮ c
    >───┤ f ├───>
        ╰───╯
  • first :: a b c -> a (b, d) (c, d)

    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)

    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

    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

    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'
Instances2Arrow
  • Monad m => Arrow (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • Arrow (->)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
newtypenewtype Kleisli (m :: Type -> Type) a b
#

Kleisli arrows of a monad.

Constructors

Instances16Category, Generic1, Arrow, ArrowApply, ArrowChoice, ArrowPlus, …

Derived combinators

valuereturnA :: Arrow a => a b b
#

The identity arrow, which plays the role of return in arrow notation.

  b
>───>
value(^>>) :: Arrow a => (b -> c) -> a c d -> a b d
#

Precomposition with a pure function.

value(>>^) :: Arrow a => a b c -> (c -> d) -> a b d
#

Postcomposition with a pure function.

value(>>>) :: Category cat => cat a b -> cat b c -> cat a c
#

Left-to-right composition. This is useful if you want to write a morphism as a pipeline going from left to right.

value(<<<) :: Category cat => cat b c -> cat a b -> cat a c
#

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

value(<<^) :: Arrow a => a c d -> (b -> c) -> a b d
#

Precomposition with a pure function (right-to-left variant).

value(^<<) :: Arrow a => (c -> d) -> a b c -> a b d
#

Postcomposition with a pure function (right-to-left variant).

Monoid operations

2 declarations

Conditionals

1 declaration
classclass Arrow a => ArrowChoice (a :: Type -> Type -> Type) where
#

Choice, for arrows that support it. This class underlies the if and case constructs in arrow notation.

Instances should satisfy the following laws:

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) dinfixr 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.

Instances2ArrowChoice
  • Monad m => ArrowChoice (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • ArrowChoice (->)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow

Arrow application

3 declarations
classclass Arrow a => ArrowApply (a :: Type -> Type -> Type) where
#

Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:

Such arrows are equivalent to monads (see ArrowMonad).

Methods

  • app :: a (a b c, b) c
Instances2ArrowApply
  • Monad m => ArrowApply (Kleisli m)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
  • ArrowApply (->)Defined in ghc-internal-10.0.0 · GHC.Internal.Control.Arrow
newtypenewtype ArrowMonad (a :: Type -> Type -> Type) 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

Instances5Monad, Functor, Applicative, Alternative, MonadPlus