Commit bc02e098 authored by Marc Coiffier's avatar Marc Coiffier
Browse files

Implement some trivial, but useful, instances for the types of foldable monads

parent 5eb98177
......@@ -2,7 +2,7 @@
-- documentation, see http://haskell.org/cabal/users-guide/
name: definitive-base
version: 2.6.2
version: 2.6.3
synopsis: A small Prelude wrapper to simplify my own Haskell developments
-- description:
license: GPL-3
......
......@@ -45,21 +45,21 @@ instance Monad m => MonadError Void (ListT m) where
l -> pure l)
newtype TreeT m a = TreeT (Compose' Tree m a)
deriving (Functor,Unit,SemiApplicative,Applicative,MonadFix,Foldable,MonadTrans)
deriving (Functor,Unit,SemiApplicative,Applicative,MonadFix,Foldable,MonadTrans,MonadReader r,MonadWriter w,MonadState s)
instance Monad m => Monad (TreeT m) where join = coerceJoin TreeT
instance Traversable m => Traversable (TreeT m) where sequence = coerceSequence TreeT
treeT :: Iso (TreeT m a) (TreeT n b) (m (Tree a)) (n (Tree b))
treeT = i'Compose'.iso TreeT (\(TreeT t) -> t)
newtype MaybeT m a = MaybeT (Compose' Maybe m a)
deriving (Functor,SemiApplicative,Unit,Applicative,MonadFix,Foldable,MonadTrans)
deriving (Semigroup,Monoid,Functor,SemiApplicative,Unit,Applicative,MonadFix,Foldable,MonadTrans,MonadReader r,MonadState s,MonadWriter w)
instance Monad m => Monad (MaybeT m) where join = coerceJoin MaybeT
instance Traversable m => Traversable (MaybeT m) where sequence = coerceSequence MaybeT
maybeT :: Iso (MaybeT m a) (MaybeT m' b) (m (Maybe a)) (m' (Maybe b))
maybeT = i'Compose'.iso MaybeT (\(MaybeT m) -> m)
newtype StrictT m a = StrictT (Compose' Strict m a)
deriving (Functor,SemiApplicative,Unit,Applicative,MonadFix,Foldable,MonadTrans)
deriving (Functor,SemiApplicative,Unit,Applicative,MonadFix,Foldable,MonadTrans,MonadReader r,MonadWriter w,MonadState s)
instance Monad m => Monad (StrictT m) where join = coerceJoin StrictT
instance Traversable m => Traversable (StrictT m) where sequence = coerceSequence StrictT
strictT :: Iso (StrictT m a) (StrictT m' b) (m (Strict a)) (m' (Strict b))
......
......@@ -58,6 +58,8 @@ class StateRes t s a | t -> s a where
instance StateRes (s,a) s a where evalS = snd ; execS = fst
instance (StateRes r a b) => StateRes (Id r) a b where evalS = evalS . getId ; execS = execS . getId
instance (StateRes r a b) => StateRes (s -> r) (s -> a) (s -> b) where evalS = map evalS ; execS = map execS
instance Functor m => StateRes (StateT s m a) (s -> m s) (s -> m a) where
execS x = map2 execS (x^..stateT) ; evalS x = map2 evalS (x^..stateT)
state :: Iso (State s a) (State t b) (s -> (s,a)) (t -> (t,b))
state = mapping i'Id.stateT
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment