@@ -25,6 +25,8 @@ import Control.Lens.SemiIso
2525infixl 3 /|/
2626infixl 4 /$/
2727infixl 5 /*/, /*, */
28+infixl 1 //=
29+infixr 1 =//
2830
2931-- | A functor from the category of semi-isomorphisms to Hask.
3032--
@@ -98,6 +100,21 @@ class SemiIsoApply f => SemiIsoAlternative f where
98100
99101 {-# MINIMAL siempty, (/|/) #-}
100102
103+class SemiIsoApply m => SemiIsoMonad m where
104+ (//=) :: m a -> (a -> m b) -> m (a, b)
105+ m //= f = swapped /$/ (f =// m)
106+
107+ (=//) :: (b -> m a) -> m b -> m (a, b)
108+ f =// m = swapped /$/ (m //= f)
109+
110+class SemiIsoMonad m => SemiIsoFix m where
111+ sifix :: (a -> m a) -> m a
112+ sifix f = dup /$/ (f =//= f)
113+ where dup = semiIso (\a -> Right (a, a)) (Right . fst)
114+
115+ (=//=) :: (a -> m b) -> (b -> m a) -> m (a, b)
116+ f =//= g = sifix (\(a, b) -> g b /*/ f a)
117+
101118-- | Equivalent of 'sequence'.
102119--
103120-- Note that it is not possible to write sequence_, because