git.iko.soy/semi-iso-optics
on master help sign in
Added SemiIsoMonad and SemiIsoFix (no docs yet).
commit743dd01742d4c51aba0d223360a60582b2b623dd authorPaweł Nowak <pawel834@gmail.com> dateThu 13 Nov 2014, 09:00 (12 years ago) parent1963cb7
1 file changed+17
Data/SemiIsoFunctor.hs+17
Data/SemiIsoFunctor.hs+17
@@ -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