@@ -33,20 +33,18 @@ module Control.SIArrow (
33 sireplicate_
33 sireplicate_
36−import Control.Arrow (Kleisli(..))
36+import Control.Arrow
37import Control.Category
37import Control.Category
38−import Control.Category.Structures
39import Control.Lens.Cons
38import Control.Lens.Cons
40import Control.Lens.Empty
39import Control.Lens.Empty
41import Control.Lens.Iso
40import Control.Lens.Iso
42import Control.Lens.SemiIso
41import Control.Lens.SemiIso
43import Control.Monad
42import Control.Monad
44import Control.Tuple.Morph
43import Control.Tuple.Morph
45−import Data.Semigroupoid.Dual
46import Prelude hiding (id, (.))
44import Prelude hiding (id, (.))
48−infixr 1 ^>>, ^<<, #>>, #<<
46+infixr 1 #>>, #<<
49−infixr 1 >>^, <<^, >>#, <<#
47+infixr 1 >>#, <<#
50infixl 4 /$/, /$~
48infixl 4 /$/, /$~
51infixl 5 /*/, */, /*
49infixl 5 /*/, */, /*
52infixl 3 /?/
50infixl 3 /?/
@@ -59,7 +57,7 @@ infixl 3 /?/
60-- The category @cat@ should contain @SemiIso@ as a sort of
58-- The category @cat@ should contain @SemiIso@ as a sort of
61-- \"subcategory of pure computations\".
59-- \"subcategory of pure computations\".
62−class (Products cat, Coproducts cat, CatPlus cat) => SIArrow cat where
60+class (Arrow cat, ArrowChoice cat, ArrowPlus cat) => SIArrow cat where
63 -- | Allows you to lift a SemiIso into @cat@. The resulting arrow should be
61 -- | Allows you to lift a SemiIso into @cat@. The resulting arrow should be
64 -- in some sense minimal or \"pure\", similiar to 'pure', 'return' and
62 -- in some sense minimal or \"pure\", similiar to 'pure', 'return' and
65 -- 'arr' from "Control.Category".
63 -- 'arr' from "Control.Category".
@@ -87,7 +85,7 @@ class (Products cat, Coproducts cat, CatPlus cat) => SIArrow cat where
88 -- | @simany v@ repeats @v@ as long as possible.
86 -- | @simany v@ repeats @v@ as long as possible.
89 simany :: cat () b -> cat () [b]
87 simany :: cat () b -> cat () [b]
90− simany v = sisome v /+/ sipure _Empty
88+ simany v = sisome v <+> sipure _Empty
92 {-# MINIMAL (siarr | sipure), sibind #-}
90 {-# MINIMAL (siarr | sipure), sibind #-}
@@ -95,32 +93,12 @@ instance MonadPlus m => SIArrow (Kleisli m) where
95 siarr ai = Kleisli $ either fail return . apply ai
93 siarr ai = Kleisli $ either fail return . apply ai
96 sibind ai = Kleisli $ \a -> either fail (($ a) . runKleisli) $ apply ai a
94 sibind ai = Kleisli $ \a -> either fail (($ a) . runKleisli) $ apply ai a
98−instance SIArrow cat => SIArrow (Dual cat) where
99− siarr = Dual . sipure
100− sibind ai = Dual $ sibind (iso id getDual . rev ai . iso getDual id)
102instance SIArrow ReifiedSemiIso' where
96instance SIArrow ReifiedSemiIso' where
103 siarr = reifySemiIso
97 siarr = reifySemiIso
104 sibind ai = ReifiedSemiIso' $
98 sibind ai = ReifiedSemiIso' $
105 semiIso (\a -> apply ai a >>= flip apply a . runSemiIso)
99 semiIso (\a -> apply ai a >>= flip apply a . runSemiIso)
106 (\b -> unapply ai b >>= flip unapply b . runSemiIso)
100 (\b -> unapply ai b >>= flip unapply b . runSemiIso)
108−-- | Composes a SemiIso with an arrow.
109−(^>>) :: SIArrow cat => ASemiIso' a b -> cat b c -> cat a c
110−f ^>> a = a . siarr f
112−-- | Composes an arrow with a SemiIso.
113−(>>^) :: SIArrow cat => cat a b -> ASemiIso' b c -> cat a c
114−a >>^ f = siarr f . a
116−-- | Composes a SemiIso with an arrow, backwards.
117−(^<<) :: SIArrow cat => ASemiIso' b c -> cat a b -> cat a c
118−f ^<< a = siarr f . a
120−-- | Composes an arrow with a SemiIso, backwards.
121−(<<^) :: SIArrow cat => cat b c -> ASemiIso' a b -> cat a c
122−a <<^ f = a . siarr f
124-- | Composes a reversed SemiIso with an arrow.
102-- | Composes a reversed SemiIso with an arrow.
125(#>>) :: SIArrow cat => ASemiIso' b a -> cat b c -> cat a c
103(#>>) :: SIArrow cat => ASemiIso' b a -> cat b c -> cat a c
126f #>> a = a . sipure f
104f #>> a = a . sipure f
@@ -171,7 +149,7 @@ ai /$<~> h = cloneSemiIso ai . reorderMorphed /$/ h
172-- The uncurried analogue of '<*>'.
150-- The uncurried analogue of '<*>'.
173(/*/) :: SIArrow cat => cat () b -> cat () c -> cat () (b, c)
151(/*/) :: SIArrow cat => cat () b -> cat () c -> cat () (b, c)
174−a /*/ b = unit ^>> (a *** b)
152+a /*/ b = siarr unit >>> (a *** b)
176-- | The product of two arrows, where the second one has no input and no output
154-- | The product of two arrows, where the second one has no input and no output
177-- (but can have side effects), with duplicate units removed. Side effect are
155-- (but can have side effects), with duplicate units removed. Side effect are
@@ -195,7 +173,7 @@ sifail = siarr . alwaysFailing
196-- | Provides an error message in the case of failure.
174-- | Provides an error message in the case of failure.
197(/?/) :: SIArrow cat => cat a b -> String -> cat a b
175(/?/) :: SIArrow cat => cat a b -> String -> cat a b
198−f /?/ msg = f /+/ sifail msg
176+f /?/ msg = f <+> sifail msg
200-- | Equivalent of 'sequence'.
178-- | Equivalent of 'sequence'.
201sisequence :: SIArrow cat => [cat () a] -> cat () [a]
179sisequence :: SIArrow cat => [cat () a] -> cat () [a]