| Copyright | (c) 2016 Alex Crough |
|---|---|
| License | BSD2 |
| Maintainer | alex@crough.io |
| Stability | Experimental |
| Portability | RankNTypes, TupleSection, TypeOperators |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Arrow.Elision
Description
- data Elision f a b
- type Elision' f a = Elision f (f a) a
- after :: (a -> f b) -> Elision f a b
- basic :: Elision' f a
- before :: (a -> b) -> Elision f (f a) b
- elide :: (a -> f c) -> (c -> b) -> Elision f a b
- terminal :: f a -> Elision f () a
- apply :: Arrow a => a b c -> b -> a () c
- complete :: Monad m => (forall c. f c -> m c) -> a -> Elision f a b -> m b
- complete' :: Monad m => (forall c. f c -> m c) -> Elision f () b -> m b
- unelide :: Monad m => Elision f a b -> (forall c. f c -> m c) -> a -> m b
- unelide' :: Monad m => Elision f () b -> (forall c. f c -> m c) -> m b
- data Sum f g a
- type (//) a b = Sum a b
- (//) :: (forall b. f b -> m b) -> (forall b. g b -> m b) -> Sum f g a -> m a
- left' :: Elision f a b -> Elision (f // g) a b
- right' :: Elision g a b -> Elision (f // g) a b
- (/>>) :: Elision f a b -> Elision g b c -> Elision (f // g) a c
- (<</) :: Elision f b c -> Elision g a b -> Elision (f // g) a c
- class Category * a => Arrow a where
- class Arrow a => ArrowApply a
- class Arrow a => ArrowChoice a where
- (***) :: 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')
- (|||) :: ArrowChoice a => forall b d c. a b d -> a c d -> a (Either b c) d
- (+++) :: ArrowChoice a => forall b c b' c'. a b c -> a b' c' -> a (Either b b') (Either c c')
- (<<<) :: Category k cat => cat b c -> cat a b -> cat a c
- (<<^) :: Arrow a => a c d -> (b -> c) -> a b d
- (^>>) :: Arrow a => (b -> c) -> a c d -> a b d
- (>>^) :: Arrow a => a b c -> (c -> d) -> a b d
- (^<<) :: Arrow a => (c -> d) -> a b c -> a b d
Types
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.
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.
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.
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
(//) :: (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.
(/>>) :: 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:
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
(***) :: 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.
class Arrow a => ArrowApply a
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) | |
| Comonad w => ArrowApply (Cokleisli w) | |
| ArrowApply (Elision f) |
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.
Minimal complete definition
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
| ArrowChoice (->) | |
| Monad m => ArrowChoice (Kleisli m) | |
| Comonad w => ArrowChoice (Cokleisli w) | |
| ArrowChoice (Elision f) | |
| (Applicative f, ArrowChoice p) => ArrowChoice (Tannen * * * f p) |
(***) :: 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.