Portability | portable |
---|---|

Stability | experimental |

Maintainer | conal@conal.net |

Safe Haskell | None |

"Deep arrows" as an `Arrow`

subclass.

- class Arrow ar => DeepArrow ar where
- result :: (b `ar` b') -> (a -> b) `ar` (a -> b')
- dupA :: a `ar` (a, a)
- fstA :: (a, b) `ar` a
- sndA :: (a, b) `ar` b
- funF :: (c -> a, b) `ar` (c -> (a, b))
- funS :: (a, c -> b) `ar` (c -> (a, b))
- funR :: (a -> c -> b) `ar` (c -> a -> b)
- curryA :: ((a, b) -> c) `ar` (a -> b -> c)
- uncurryA :: (a -> b -> c) `ar` ((a, b) -> c)
- swapA :: (a, b) `ar` (b, a)
- lAssocA :: (a, (b, c)) `ar` ((a, b), c)
- rAssocA :: ((a, b), c) `ar` (a, (b, c))

- funFirst :: DeepArrow ar => (a `ar` (d -> a')) -> (a, b) `ar` (d -> (a', b))
- funSecond :: DeepArrow ar => (b `ar` (d -> b')) -> (a, b) `ar` (d -> (a, b'))
- funResult :: DeepArrow ar => (b `ar` (d -> b')) -> (a -> b) `ar` (d -> a -> b')
- inpF :: DeepArrow ar => ((a, b) -> c) `ar` (a -> b -> c)
- inpS :: DeepArrow ar => ((a, b) -> c) `ar` (b -> a -> c)
- inpFirst :: DeepArrow ar => ((a -> c) `ar` (d -> a' -> c)) -> ((a, b) -> c) `ar` (d -> (a', b) -> c)
- inpSecond :: DeepArrow ar => ((b -> c) `ar` (d -> b' -> c)) -> ((a, b) -> c) `ar` (d -> (a, b') -> c)
- flipA :: DeepArrow ar => (a -> c -> b) `ar` (c -> a -> b)
- unzipA :: DeepArrow ar => (a `ar` (b, c)) -> (a `ar` b, a `ar` c)
- class FunAble h => FunDble h where
- resultFun :: (h b -> h b') -> h (a -> b) -> h (a -> b')
- dupAFun :: h a -> h (a, a)
- fstAFun :: h (a, b) -> h a
- sndAFun :: h (a, b) -> h b
- funFFun :: h (c -> a, b) -> h (c -> (a, b))
- funSFun :: h (a, c -> b) -> h (c -> (a, b))
- funRFun :: h (a -> c -> b) -> h (c -> a -> b)
- curryAFun :: h ((a, b) -> c) -> h (a -> b -> c)
- uncurryAFun :: h (a -> b -> c) -> h ((a, b) -> c)
- swapAFun :: h (a, b) -> h (b, a)
- lAssocAFun :: h (a, (b, c)) -> h ((a, b), c)
- rAssocAFun :: h ((a, b), c) -> h (a, (b, c))

- (->|) :: (DeepArrow ar, FunArr ar w) => w (a -> b) -> w (b -> c) -> w (a -> c)

# The DeepArrow class

class Arrow ar => DeepArrow ar whereSource

Arrows for deep application. Most of these methods could be defined
using `arr`

, but `arr`

is not definable for some types. If your
`DeepArrow`

instance has `arr`

, you might want to use these
implementations

`fstA`

=`arr`

`fst`

`dupA`

=`arr`

(\ x -> (x,x))`sndA`

=`arr`

`snd`

`funF`

=`arr`

(\ (f,b) -> \ c -> (f c, b))`funS`

=`arr`

(\ (a,f) -> \ c -> (a, f c))`funR`

=`arr`

`flip`

`curryA`

=`arr`

`curry`

`uncurryA`

=`arr`

`uncurry`

`swapA`

=`arr`

(\ (a,b) -> (b,a))`lAssocA`

=`arr`

(\ (a,(b,c)) -> ((a,b),c))`rAssocA`

=`arr`

(\ ((a,b),c) -> (a,(b,c)))

If your `DeepArrow`

instance *does not* have `arr`

, you'll have to come up
with other definitions. In any case, I recommend the following
definitions, which mirror `Arrow`

defaults while avoiding `arr`

. Be sure
also to define `arr`

or `pure`

to yield an error message (rather than
ping-ponging infinitely between them via the `Arrow`

default definitions).

`second`

f =`swapA`

`.`

`first`

f`.`

`swapA`

f`&&&`

g =`dupA`

`>>>`

f`***`

g

In a few cases, there are default methods, as noted below. The
defaults do not use `arr`

.

result :: (b `ar` b') -> (a -> b) `ar` (a -> b')Source

Duplicate.

Extract first.

Extract second.

funF :: (c -> a, b) `ar` (c -> (a, b))Source

Extract function from first element.

funS :: (a, c -> b) `ar` (c -> (a, b))Source

Extract function from second element.

funR :: (a -> c -> b) `ar` (c -> a -> b)Source

Extract function from result.

curryA :: ((a, b) -> c) `ar` (a -> b -> c)Source

Curry arrow.

uncurryA :: (a -> b -> c) `ar` ((a, b) -> c)Source

Uncurry arrow.

swapA :: (a, b) `ar` (b, a)Source

Swap elements. Has default.

lAssocA :: (a, (b, c)) `ar` ((a, b), c)Source

Left-associate. Has default.

rAssocA :: ((a, b), c) `ar` (a, (b, c))Source

Right-associate. Has default.

# Composable function extractors

funFirst :: DeepArrow ar => (a `ar` (d -> a')) -> (a, b) `ar` (d -> (a', b))Source

Promote a function extractor into one that reaches into the first element of a pair.

funSecond :: DeepArrow ar => (b `ar` (d -> b')) -> (a, b) `ar` (d -> (a, b'))Source

Promote a function extractor into one that reaches into the second element of a pair.

funResult :: DeepArrow ar => (b `ar` (d -> b')) -> (a -> b) `ar` (d -> a -> b')Source

Promote a function extractor into one that reaches into the result element of a function.

# Composable input extractors

inpF :: DeepArrow ar => ((a, b) -> c) `ar` (a -> b -> c)Source

Extract the first component of a pair input.

inpS :: DeepArrow ar => ((a, b) -> c) `ar` (b -> a -> c)Source

Extract the second component of a pair input.

inpFirst :: DeepArrow ar => ((a -> c) `ar` (d -> a' -> c)) -> ((a, b) -> c) `ar` (d -> (a', b) -> c)Source

Given a way to extract a `d`

input from an `a`

input, leaving an `a'`

residual input, `inpFirst`

yields a way to extract a `d`

input from an
`(a,b)`

input, leaving an `(a',b)`

residual input.

inpSecond :: DeepArrow ar => ((b -> c) `ar` (d -> b' -> c)) -> ((a, b) -> c) `ar` (d -> (a, b') -> c)Source

Analogous to `inpFirst`

.

# Misc functions

`DeepArrow`

instance helper

class FunAble h => FunDble h whereSource

resultFun :: (h b -> h b') -> h (a -> b) -> h (a -> b')Source

dupAFun :: h a -> h (a, a)Source

fstAFun :: h (a, b) -> h aSource

sndAFun :: h (a, b) -> h bSource

funFFun :: h (c -> a, b) -> h (c -> (a, b))Source

funSFun :: h (a, c -> b) -> h (c -> (a, b))Source

funRFun :: h (a -> c -> b) -> h (c -> a -> b)Source

curryAFun :: h ((a, b) -> c) -> h (a -> b -> c)Source

uncurryAFun :: h (a -> b -> c) -> h ((a, b) -> c)Source

swapAFun :: h (a, b) -> h (b, a)Source

lAssocAFun :: h (a, (b, c)) -> h ((a, b), c)Source

rAssocAFun :: h ((a, b), c) -> h (a, (b, c))Source