@@ -0,0 +1,37 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+Module : Data.SemiIsoFunctor.Wrapped
5+Description : SemiIso instances for wrapped monads.
6+Copyright : (c) Paweł Nowak
9+Maintainer : Paweł Nowak <pawel834@gmail.com>
10+Stability : experimental
12+Every monad (with fail) is a SemiIsoMonad.
14+module Data.SemiIsoFunctor.Wrapped where
16+import Control.Applicative
17+import Control.Lens.SemiIso
19+import Data.SemiIsoFunctor
21+-- | A wrapped covariant functor.
22+newtype WrappedCovariant m a = WrappedCovariant { runCovariant :: m a }
23+ deriving (Functor, Applicative, Alternative, Monad)
25+instance Monad m => SemiIsoFunctor (WrappedCovariant m) where
26+ simapCo ai m = m >>= either fail return . apply ai
28+instance Monad m => SemiIsoApply (WrappedCovariant m) where
29+ sipure ai = either fail return (unapply ai ())
30+ f /*/ g = liftM2 (,) f g
32+instance (Monad m, Alternative m) => SemiIsoAlternative (WrappedCovariant m) where
36+instance Monad m => SemiIsoMonad (WrappedCovariant m) where
37+ f //= g = f >>= (\x -> g x >>= \y -> return (x, y))