module Control.Arrow.ArrowList
( ArrowList(..)
)
where
import Control.Arrow
infixl 8 >>., >.
infixl 2 $<, $<<, $<<<, $<<<<
infixl 2 $<$
class (Arrow a, ArrowPlus a, ArrowZero a, ArrowApply a) => ArrowList a where
arr2 :: (b1 -> b2 -> c) -> a (b1, b2) c
arr2 = ((b1, b2) -> c) -> a (b1, b2) c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (((b1, b2) -> c) -> a (b1, b2) c)
-> ((b1 -> b2 -> c) -> (b1, b2) -> c)
-> (b1 -> b2 -> c)
-> a (b1, b2) c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b1 -> b2 -> c) -> (b1, b2) -> c
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry
{-# INLINE arr2 #-}
arr3 :: (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c
arr3 b1 -> b2 -> b3 -> c
f = ((b1, (b2, b3)) -> c) -> a (b1, (b2, b3)) c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\ ~(b1
x1, ~(b2
x2, b3
x3)) -> b1 -> b2 -> b3 -> c
f b1
x1 b2
x2 b3
x3)
{-# INLINE arr3 #-}
arr4 :: (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c
arr4 b1 -> b2 -> b3 -> b4 -> c
f = ((b1, (b2, (b3, b4))) -> c) -> a (b1, (b2, (b3, b4))) c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\ ~(b1
x1, ~(b2
x2, ~(b3
x3, b4
x4))) -> b1 -> b2 -> b3 -> b4 -> c
f b1
x1 b2
x2 b3
x3 b4
x4)
{-# INLINE arr4 #-}
arr2A :: (b -> a c d) -> a (b, c) d
arr2A b -> a c d
f = a b (a c d) -> a (b, c) (a c d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ((b -> a c d) -> a b (a c d)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> a c d
f) a (b, c) (a c d, c) -> a (a c d, c) d -> a (b, c) d
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> a (a c d, c) d
forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
app
{-# INLINE arr2A #-}
arrL :: (b -> [c]) -> a b c
arr2L :: (b -> c -> [d]) -> a (b, c) d
arr2L = ((b, c) -> [d]) -> a (b, c) d
forall (a :: * -> * -> *) b c. ArrowList a => (b -> [c]) -> a b c
arrL (((b, c) -> [d]) -> a (b, c) d)
-> ((b -> c -> [d]) -> (b, c) -> [d])
-> (b -> c -> [d])
-> a (b, c) d
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (b -> c -> [d]) -> (b, c) -> [d]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry
{-# INLINE arr2L #-}
constA :: c -> a b c
constA = (b -> c) -> a b c
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((b -> c) -> a b c) -> (c -> b -> c) -> c -> a b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> b -> c
forall a b. a -> b -> a
const
{-# INLINE constA #-}
constL :: [c] -> a b c
constL = (b -> [c]) -> a b c
forall (a :: * -> * -> *) b c. ArrowList a => (b -> [c]) -> a b c
arrL ((b -> [c]) -> a b c) -> ([c] -> b -> [c]) -> [c] -> a b c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [c] -> b -> [c]
forall a b. a -> b -> a
const
{-# INLINE constL #-}
isA :: (b -> Bool) -> a b b
(>>.) :: a b c -> ([c] -> [d]) -> a b d
(>.) :: a b c -> ([c] -> d ) -> a b d
a b c
af >. [c] -> d
f = a b c
af a b c -> ([c] -> [d]) -> a b d
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> [d]) -> a b d
>>. ((d -> [d] -> [d]
forall a. a -> [a] -> [a]
:[]) (d -> [d]) -> ([c] -> d) -> [c] -> [d]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [c] -> d
f)
{-# INLINE (>.) #-}
listA :: a b c -> a b [c]
listA a b c
af = a b c
af a b c -> ([c] -> [[c]]) -> a b [c]
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> [d]) -> a b d
>>. ([c] -> [[c]] -> [[c]]
forall a. a -> [a] -> [a]
:[])
{-# INLINE listA #-}
unlistA :: a [b] b
unlistA = ([b] -> [b]) -> a [b] b
forall (a :: * -> * -> *) b c. ArrowList a => (b -> [c]) -> a b c
arrL [b] -> [b]
forall a. a -> a
id
{-# INLINE unlistA #-}
this :: a b b
this = a b b
forall (a :: * -> * -> *) b. Arrow a => a b b
returnA
{-# INLINE this #-}
none :: a b c
none = a b c
forall (a :: * -> * -> *) b c. ArrowZero a => a b c
zeroArrow
{-# INLINE none #-}
withDefault :: a b c -> c -> a b c
withDefault a b c
a c
d = a b c
a a b c -> ([c] -> [c]) -> a b c
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> [d]) -> a b d
>>. \ [c]
x -> if [c] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [c]
x then [c
d] else [c]
x
{-# INLINE withDefault #-}
single :: a b c -> a b c
single a b c
f = a b c
f a b c -> ([c] -> [c]) -> a b c
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> [d]) -> a b d
>>. Int -> [c] -> [c]
forall a. Int -> [a] -> [a]
take Int
1
applyA :: a b (a b c) -> a b c
applyA a b (a b c)
f = (a b (a b c)
f a b (a b c) -> a b b -> a b (a b c, b)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& a b b
forall (a :: * -> * -> *) b. ArrowList a => a b b
this) a b (a b c, b) -> a (a b c, b) c -> a b c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> a (a b c, b) c
forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
app
($<) :: (c -> a b d) -> a b c -> a b d
c -> a b d
g $< a b c
f = a b (a b d) -> a b d
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (a b c
f a b c -> a c (a b d) -> a b (a b d)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (c -> a b d) -> a c (a b d)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr c -> a b d
g)
($<<) :: (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
c1 -> c2 -> a b d
f $<< a b (c1, c2)
g = a b (a b d) -> a b d
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (a b (c1, c2)
g a b (c1, c2) -> a (c1, c2) (a b d) -> a b (a b d)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (c1 -> c2 -> a b d) -> a (c1, c2) (a b d)
forall (a :: * -> * -> *) b1 b2 c.
ArrowList a =>
(b1 -> b2 -> c) -> a (b1, b2) c
arr2 c1 -> c2 -> a b d
f)
($<<<) :: (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b d
c1 -> c2 -> c3 -> a b d
f $<<< a b (c1, (c2, c3))
g = a b (a b d) -> a b d
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (a b (c1, (c2, c3))
g a b (c1, (c2, c3)) -> a (c1, (c2, c3)) (a b d) -> a b (a b d)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (c1 -> c2 -> c3 -> a b d) -> a (c1, (c2, c3)) (a b d)
forall (a :: * -> * -> *) b1 b2 b3 c.
ArrowList a =>
(b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c
arr3 c1 -> c2 -> c3 -> a b d
f)
($<<<<) :: (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b d
c1 -> c2 -> c3 -> c4 -> a b d
f $<<<< a b (c1, (c2, (c3, c4)))
g = a b (a b d) -> a b d
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (a b (c1, (c2, (c3, c4)))
g a b (c1, (c2, (c3, c4)))
-> a (c1, (c2, (c3, c4))) (a b d) -> a b (a b d)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (c1 -> c2 -> c3 -> c4 -> a b d) -> a (c1, (c2, (c3, c4))) (a b d)
forall (a :: * -> * -> *) b1 b2 b3 b4 c.
ArrowList a =>
(b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c
arr4 c1 -> c2 -> c3 -> c4 -> a b d
f)
($<$) :: (c -> (a b b)) -> a b c -> a b b
c -> a b b
g $<$ a b c
f = a b (a b b) -> a b b
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (a b (a b b) -> a b [a b b]
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b [c]
listA (a b c
f a b c -> a c (a b b) -> a b (a b b)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (c -> a b b) -> a c (a b b)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr c -> a b b
g) a b [a b b] -> a [a b b] (a b b) -> a b (a b b)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ([a b b] -> a b b) -> a [a b b] (a b b)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr [a b b] -> a b b
forall (a :: * -> * -> *) b. ArrowList a => [a b b] -> a b b
seqA)
mergeA :: (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) ->
a (a1, b1) c
mergeA a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c
op = (\ (a1, b1)
x -> ((a1, b1) -> a1) -> a (a1, b1) a1
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (a1, b1) -> a1
forall a b. (a, b) -> a
fst a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c
`op` b1 -> a (a1, b1) b1
forall (a :: * -> * -> *) c b. ArrowList a => c -> a b c
constA ((a1, b1) -> b1
forall a b. (a, b) -> b
snd (a1, b1)
x)) ((a1, b1) -> a (a1, b1) c) -> a (a1, b1) (a1, b1) -> a (a1, b1) c
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< a (a1, b1) (a1, b1)
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
perform :: a b c -> a b b
perform a b c
f = a b c -> a b [c]
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b [c]
listA a b c
f a b [c] -> a b b -> a b ([c], b)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& a b b
forall (a :: * -> * -> *) b. ArrowList a => a b b
this a b ([c], b) -> a ([c], b) b -> a b b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (([c], b) -> b) -> a ([c], b) b
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ([c], b) -> b
forall a b. (a, b) -> b
snd
{-# INLINE perform #-}
catA :: [a b c] -> a b c
catA = (a b c -> a b c -> a b c) -> a b c -> [a b c] -> a b c
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl a b c -> a b c -> a b c
forall (a :: * -> * -> *) b c.
ArrowPlus a =>
a b c -> a b c -> a b c
(<+>) a b c
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none
{-# INLINE catA #-}
seqA :: [a b b] -> a b b
seqA = (a b b -> a b b -> a b b) -> a b b -> [a b b] -> a b b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl a b b -> a b b -> a b b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
(>>>) a b b
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
{-# INLINE seqA #-}