elision-0.1.2.0: Arrows with holes.

Copyright(c) 2016 Alex Crough
LicenseBSD2
Maintaineralex@crough.io
StabilityExperimental
PortabilityRankNTypes, TupleSection, TypeOperators
Safe HaskellSafe
LanguageHaskell2010

Control.Arrow.Elision

Contents

Description

 

Synopsis

Types

data Elision f a b Source

A lens-esque type that can be used to "skip" part of a function.

An Elision can be used in the common interpreter pattern, in which case f represents the DSL type, a represents the input of a function and b represents the output.

Use complete or unelide to deconstruct the type.

type Elision' f a = Elision f (f a) a Source

The type of the simplist elision, where unelide eli f = f

Constructors

after :: (a -> f b) -> Elision f a b Source

Create an elision chained to the end of the provided function.

basic :: Elision' f a Source

The simplest elision, effectively the identity function.

before :: (a -> b) -> Elision f (f a) b Source

Create an elision chained to the beginning of the provided function.

elide :: (a -> f c) -> (c -> b) -> Elision f a b Source

Create an elision out of two functions to be completed at a later date.

terminal :: f a -> Elision f () a Source

Create an elision with the input fully applied.

Manipulation

apply :: Arrow a => a b c -> b -> a () c Source

Apply an argument to an arrow and close off the input.

complete :: Monad m => (forall c. f c -> m c) -> a -> Elision f a b -> m b Source

Construct an interpreter for an elision out of a function an initial argument.

complete' :: Monad m => (forall c. f c -> m c) -> Elision f () b -> m b Source

Like complete, but the unit type never has to be provided.

unelide :: Monad m => Elision f a b -> (forall c. f c -> m c) -> a -> m b Source

Deconstruct an Elision, returning its inner type.

unelide' :: Monad m => Elision f () b -> (forall c. f c -> m c) -> m b Source

Like unelide, but applies the unit type to the function immediately.

Combining Interpreters

data Sum f g a Source

Either f a or g a.

type (//) a b = Sum a b infixr 2 Source

A type synonym for Sum to create harmony with the // function.

(//) :: (forall b. f b -> m b) -> (forall b. g b -> m b) -> Sum f g a -> m a infixr 2 Source

Create a function that can complete an elision of a sum out of two functions that can complete each individual parts.

left' :: Elision f a b -> Elision (f // g) a b Source

Like left, but over the first type argument.

right' :: Elision g a b -> Elision (f // g) a b Source

Like right, but over the first type argument.

(/>>) :: Elision f a b -> Elision g b c -> Elision (f // g) a c infixr 4 Source

Send the output of the left to the input of right, and add their f types together.

This is analogous to a lifted '(>>>)'.

(<</) :: Elision f b c -> Elision g a b -> Elision (f // g) a c infixr 4 Source

Send the output of the right to the input of the left, and add their f types together.

This is analogous to a lifted '(>>>)'.

Arrow combinator re-exports

class Category * a => Arrow a 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.

Minimal complete definition

arr, first

Methods

(***) :: 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.

Instances

Arrow (->) 
Monad m => Arrow (Kleisli m) 
Comonad w => Arrow (Cokleisli w) 
Arrow (Elision f) 
(Applicative f, Arrow p) => Arrow (Tannen * * * f p) 

class Arrow a => ArrowApply a

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

Such arrows are equivalent to monads (see ArrowMonad).

Minimal complete definition

app

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:

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

(+++) :: 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

(***) :: 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.

(|||) :: 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.

(+++) :: 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.

(<<<) :: Category k cat => cat b c -> cat a b -> cat a c infixr 1

Right-to-left composition

(<<^) :: Arrow a => a c d -> (b -> c) -> a b d infixr 1

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

(^>>) :: Arrow a => (b -> c) -> a c d -> a b d infixr 1

Precomposition with a pure function.

(>>^) :: Arrow a => a b c -> (c -> d) -> a b d infixr 1

Postcomposition with a pure function.

(^<<) :: Arrow a => (c -> d) -> a b c -> a b d infixr 1

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