module Rattus.Arrow where
import Prelude hiding (id)
import Rattus.Primitives
import Control.Category
class Category a => Arrow a where
{-# MINIMAL arrBox, (first | (***)) #-}
arrBox :: Box (b -> c) -> a b c
first :: a b c -> a (b,d) (c,d)
first = (forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id)
second :: a b c -> a (d,b) (d,c)
second = (forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
***)
(***) :: a b c -> a b' c' -> a (b,b') (c,c')
a b c
f *** a b' c'
g = forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first a b c
f forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall {b} {a}. (b, a) -> (a, b)
swap forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first a b' c'
g forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr forall {b} {a}. (b, a) -> (a, b)
swap
where swap :: (b, a) -> (a, b)
swap ~(b
x,a
y) = (a
y,b
x)
(&&&) :: a b c -> a b c' -> a b (c,c')
a b c
f &&& a b c'
g = forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\b
b -> (b
b,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 c
f forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** a b c'
g
arr :: Arrow a => (b -> c) -> a b c
arr :: forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr b -> c
f = forall (a :: * -> * -> *) b c. Arrow a => Box (b -> c) -> a b c
arrBox (forall a. a -> Box a
box b -> c
f)
returnA :: Arrow a => a b b
returnA :: forall (a :: * -> * -> *) b. Arrow a => a b b
returnA = forall (a :: * -> * -> *) b c. Arrow a => Box (b -> c) -> a b c
arrBox (forall a. a -> Box a
box forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
id)