base-4.16.0.0: Basic libraries
Copyright(c) Ross Paterson 2002
LicenseBSD-style (see the LICENSE file in the distribution)
Maintainerlibraries@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellTrustworthy
LanguageHaskell2010

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

Arrows

class Category a => Arrow a where Source #

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.

Minimal complete definition

arr, (first | (***))

Methods

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.

Instances

Instances details
Monad m => Arrow (Kleisli m) #

Since: base-2.1

Instance details

Defined in 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 #

Arrow (->) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> b -> c Source #

first :: (b -> c) -> (b, d) -> (c, d) Source #

second :: (b -> c) -> (d, b) -> (d, c) Source #

(***) :: (b -> c) -> (b' -> c') -> (b, b') -> (c, c') Source #

(&&&) :: (b -> c) -> (b -> c') -> b -> (c, c') Source #

newtype Kleisli m a b Source #

Kleisli arrows of a monad.

Constructors

Kleisli 

Fields

Instances

Instances details
Monad m => Category (Kleisli m :: Type -> Type -> TYPE LiftedRep) #

Since: base-3.0

Instance details

Defined in Control.Arrow

Methods

id :: forall (a :: k). Kleisli m a a Source #

(.) :: forall (b :: k) (c :: k) (a :: k). Kleisli m b c -> Kleisli m a b -> Kleisli m a c Source #

Generic1 (Kleisli m a :: Type -> TYPE LiftedRep) # 
Instance details

Defined in Control.Arrow

Associated Types

type Rep1 (Kleisli m a) :: k -> Type Source #

Methods

from1 :: forall (a0 :: k). Kleisli m a a0 -> Rep1 (Kleisli m a) a0 Source #

to1 :: forall (a0 :: k). Rep1 (Kleisli m a) a0 -> Kleisli m a a0 Source #

Monad m => Arrow (Kleisli m) #

Since: base-2.1

Instance details

Defined in 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) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c Source #

Monad m => ArrowChoice (Kleisli m) #

Since: base-2.1

Instance details

Defined in 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 #

MonadFix m => ArrowLoop (Kleisli m) #

Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class.

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c Source #

MonadPlus m => ArrowPlus (Kleisli m) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c Source #

MonadPlus m => ArrowZero (Kleisli m) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c Source #

Alternative m => Alternative (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

empty :: Kleisli m a a0 Source #

(<|>) :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 Source #

some :: Kleisli m a a0 -> Kleisli m a [a0] Source #

many :: Kleisli m a a0 -> Kleisli m a [a0] Source #

Applicative m => Applicative (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in 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) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b Source #

(<$) :: a0 -> Kleisli m a b -> Kleisli m a a0 Source #

Monad m => Monad (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

(>>=) :: Kleisli m a a0 -> (a0 -> Kleisli m a b) -> Kleisli m a b Source #

(>>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b Source #

return :: a0 -> Kleisli m a a0 Source #

MonadPlus m => MonadPlus (Kleisli m a) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: Kleisli m a a0 Source #

mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 Source #

Generic (Kleisli m a b) # 
Instance details

Defined in Control.Arrow

Associated Types

type Rep (Kleisli m a b) :: Type -> Type Source #

Methods

from :: Kleisli m a b -> Rep (Kleisli m a b) x Source #

to :: Rep (Kleisli m a b) x -> Kleisli m a b Source #

type Rep1 (Kleisli m a :: Type -> TYPE LiftedRep) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

type Rep1 (Kleisli m a :: Type -> TYPE LiftedRep) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) ((FUN 'Many a :: TYPE LiftedRep -> Type) :.: Rec1 m)))
type Rep (Kleisli m a b) #

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

type Rep (Kleisli m a b) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m b))))

Derived combinators

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

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 Arrow a => ArrowZero a where Source #

Methods

zeroArrow :: a b c Source #

Instances

Instances details
MonadPlus m => ArrowZero (Kleisli m) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c Source #

class ArrowZero a => ArrowPlus a where Source #

A monoid on arrows.

Methods

(<+>) :: a b c -> a b c -> a b c infixr 5 Source #

An associative operation with identity zeroArrow.

Instances

Instances details
MonadPlus m => ArrowPlus (Kleisli m) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c Source #

Conditionals

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:

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.

Minimal complete definition

(left | (+++))

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

Instances details
Monad m => ArrowChoice (Kleisli m) #

Since: base-2.1

Instance details

Defined in 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 #

ArrowChoice (->) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

left :: (b -> c) -> Either b d -> Either c d Source #

right :: (b -> c) -> Either d b -> Either d c Source #

(+++) :: (b -> c) -> (b' -> c') -> Either b b' -> Either c c' Source #

(|||) :: (b -> d) -> (c -> d) -> Either b c -> d Source #

Arrow application

class Arrow a => ArrowApply a where Source #

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 Source #

Instances

Instances details
Monad m => ArrowApply (Kleisli m) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c Source #

ArrowApply (->) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: (b -> c, b) -> c Source #

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.

Constructors

ArrowMonad (a () b) 

Instances

Instances details
ArrowPlus a => Alternative (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

empty :: ArrowMonad a a0 Source #

(<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 Source #

some :: ArrowMonad a a0 -> ArrowMonad a [a0] Source #

many :: ArrowMonad a a0 -> ArrowMonad a [a0] Source #

Arrow a => Applicative (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

pure :: a0 -> ArrowMonad a a0 Source #

(<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source #

liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c Source #

(*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source #

(<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 Source #

Arrow a => Functor (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b Source #

(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 Source #

ArrowApply a => Monad (ArrowMonad a) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b Source #

(>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b Source #

return :: a0 -> ArrowMonad a a0 Source #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) #

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: ArrowMonad a a0 Source #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 Source #

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.

Feedback

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:

extension
loop (arr f) = arr (\ b -> fst (fix (\ (c,d) -> f (b,d))))
left tightening
loop (first h >>> f) = h >>> loop f
right tightening
loop (f >>> first h) = loop f >>> h
sliding
loop (f >>> arr (id *** k)) = loop (arr (id *** k) >>> f)
vanishing
loop (loop f) = loop (arr unassoc >>> f >>> arr assoc)
superposing
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)

Methods

loop :: a (b, d) (c, d) -> a b c Source #

Instances

Instances details
MonadFix m => ArrowLoop (Kleisli m) #

Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class.

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c Source #

ArrowLoop (->) #

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: ((b, d) -> (c, d)) -> b -> c Source #