@@ -1,5 +1,4 @@
1{-# LANGUAGE TypeFamilies #-}
1{-# LANGUAGE TypeFamilies #-}
2−{-# LANGUAGE PatternSynonyms #-}
3{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ConstraintKinds #-}
5Module : Control.SIArrow
4Module : Control.SIArrow
@@ -10,15 +9,12 @@ License : MIT
10Maintainer : Paweł Nowak <pawel834@gmail.com>
9Maintainer : Paweł Nowak <pawel834@gmail.com>
11Stability : experimental
10Stability : experimental
13−It can be instantiated by both covariant (like Parser) and contravariant
14−(like Printer) functors. Therefore it can be used as a common interface to unify
15−parsing and pretty printing.
17module Control.SIArrow where
13module Control.SIArrow where
19import Control.Arrow (Kleisli(..))
15import Control.Arrow (Kleisli(..))
20−import qualified Control.Arrow as BadArrow
21import Control.Category
16import Control.Category
17+import Control.Category.Structures
22import Control.Lens.Cons
18import Control.Lens.Cons
23import Control.Lens.Empty
19import Control.Lens.Empty
24import Control.Lens.SemiIso
20import Control.Lens.SemiIso
@@ -26,9 +22,6 @@ import Control.Monad
26import Data.Tuple.Morph
22import Data.Tuple.Morph
27import Prelude hiding (id, (.))
23import Prelude hiding (id, (.))
32infixr 1 ^>>, >>^
25infixr 1 ^>>, >>^
33infixr 1 ^<<, <<^
26infixr 1 ^<<, <<^
34infixl 4 /$/, /$~, ~$/, ~$~
27infixl 4 /$/, /$~, ~$/, ~$~
@@ -36,31 +29,7 @@ infixl 5 /*/, */, /*
37-- Categories.
30-- Categories.
39−class Category cat => Products cat where
40− first :: cat a b -> cat (a, c) (b, c)
43− second :: cat a b -> cat (c, a) (c, b)
46− (***) :: cat a b -> cat c d -> cat (a, c) (b, d)
47− a *** b = first a >>> second b
49−class Category cat => Coproducts cat where
50− left :: cat a b -> cat (Either a c) (Either b c)
53− right :: cat a b -> cat (Either c a) (Either c b)
56− (+++) :: cat a b -> cat c d -> cat (Either a c) (Either b d)
57− a +++ b = left a >>> right b
59−class Category cat => CategoryPlus cat where
61− (/+/) :: cat a b -> cat a b -> cat a b
63−class (Products cat, Coproducts cat, CategoryPlus cat) => SIArrow cat where
32+class (Products cat, Coproducts cat, CatPlus cat) => SIArrow cat where
64 siarr :: ASemiIso' a b -> cat a b
33 siarr :: ASemiIso' a b -> cat a b
66 sipure :: ASemiIso' b a -> cat a b
35 sipure :: ASemiIso' b a -> cat a b
@@ -72,21 +41,6 @@ class (Products cat, Coproducts cat, CategoryPlus cat) => SIArrow cat where
72 simany :: cat () b -> cat () [b]
41 simany :: cat () b -> cat () [b]
73 simany v = sisome v /+/ sipure _Empty
42 simany v = sisome v /+/ sipure _Empty
75−class CategoryTrans t where
76− clift :: Category cat => cat a b -> t cat a b
80−instance Monad m => Products (Kleisli m) where
81− (***) = (BadArrow.***)
83−instance Monad m => Coproducts (Kleisli m) where
84− (+++) = (BadArrow.+++)
86−instance MonadPlus m => CategoryPlus (Kleisli m) where
87− cempty = BadArrow.zeroArrow
88− (/+/) = (BadArrow.<+>)
90instance MonadPlus m => SIArrow (Kleisli m) where
44instance MonadPlus m => SIArrow (Kleisli m) where
91 siarr ai = Kleisli $ either fail return . apply ai
45 siarr ai = Kleisli $ either fail return . apply ai