on master help sign in
EtherStateT/EtherReaderT mutual instances
commit09a47def93a9426030659a7af5da602bdb3d7063 authorIndex Int <vlad.z.4096@gmail.com> dateWed 10 Jun 2015, 13:03 (11 years ago) parent217021c
3 files changed+27
src/Control/Monad/Ether/Reader.hs+7 src/Control/Monad/Ether/State.hs+8 test/Regression.hs+12
src/Control/Monad/Ether/Reader.hs+7
@@ -34,6 +34,7 @@ module Control.Monad.Ether.Reader
3434import Data.Proxy (Proxy(Proxy))
3535import Control.Monad.Trans (lift)
3636
37+import Control.Monad.Trans.Ether.State (EtherStateT, mapEtherStateT)
3738import Control.Monad.Trans.Ether.Reader
3839
3940-- for mtl instances
@@ -79,6 +80,12 @@ instance (MonadEtherReader tag r m) => MonadEtherReader tag r (EtherReaderT tag'
7980 etherAsk proxy = lift (etherAsk proxy)
8081 etherLocal proxy = mapEtherReaderT Proxy . etherLocal proxy
8182
83+-- Instances for other tagged transformers
84+
85+instance (MonadEtherReader tag r m) => MonadEtherReader tag r (EtherStateT tag' s m) where
86+ etherAsk proxy = lift (etherAsk proxy)
87+ etherLocal proxy = mapEtherStateT Proxy . etherLocal proxy
88+
8289-- Instances for mtl transformers
8390
8491instance MonadEtherReader tag r m => MonadEtherReader tag r (Trans.ContT r' m) where
src/Control/Monad/Ether/State.hs+8
@@ -36,6 +36,7 @@ module Control.Monad.Ether.State
3636import Data.Proxy (Proxy(Proxy))
3737import Control.Monad.Trans (lift)
3838
39+import Control.Monad.Trans.Ether.Reader (EtherReaderT)
3940import Control.Monad.Trans.Ether.State
4041
4142-- for mtl instances
@@ -93,6 +94,13 @@ instance (MonadEtherState tag s m) => MonadEtherState tag s (EtherStateT tag' s'
9394 etherPut proxy = lift . etherPut proxy
9495 etherState proxy = lift . etherState proxy
9596
97+-- Instances for other tagged transformers
98+
99+instance (MonadEtherState tag s m) => MonadEtherState tag s (EtherReaderT tag' r m) where
100+ etherGet proxy = lift (etherGet proxy)
101+ etherPut proxy = lift . etherPut proxy
102+ etherState proxy = lift . etherState proxy
103+
96104-- Instances for mtl transformers
97105
98106instance MonadEtherState tag s m => MonadEtherState tag s (Trans.ContT r m) where
test/Regression.hs+12
@@ -8,9 +8,11 @@ module Main where
88
99import Data.Proxy
1010
11+import Control.Ether.Core
1112import Control.Ether.TH
1213import Control.Ether.Wrapped
1314import Control.Monad.Ether.Reader
15+import Control.Monad.Ether.State
1416import Control.Monad.Reader
1517
1618import Test.Tasty
@@ -92,3 +94,13 @@ uniqueTagsCore = flip runReader1T (1 :: Int)
9294 print a
9395 print b
9496 print c
97+
98+data TagState1
99+
100+stateCore :: ( MonadEtherState TagState1 Int m
101+ , MonadEtherReader TagReader1 Int m
102+ , UniqueEtherTags m ) => m ()
103+stateCore = do
104+ a <- etherAsk (Proxy :: Proxy TagReader1)
105+ n <- etherGet (Proxy :: Proxy TagState1)
106+ etherPut (Proxy :: Proxy TagState1) (n * a)