on master help sign in
Wrap MonadEtherReader to get MonadReader
commit650c7de488566cf8bca695a4bdfa10cef8af11b9 authorIndex Int <vlad.z.4096@gmail.com> dateMon 8 Jun 2015, 22:47 (11 years ago) parentd8b183b
4 files changed+39
ether.cabal+1 src/Control/Ether/Wrapped.hs+27 src/Control/Monad/Ether/Reader.hs+1 test/Regression.hs+10
ether.cabal+1
@@ -16,6 +16,7 @@ library
1616
1717 exposed-modules: Control.Ether.Core
1818 Control.Ether.TH
19+ Control.Ether.Wrapped
1920 Control.Monad.Trans.Ether.Reader
2021 Control.Monad.Ether.Reader
2122
src/Control/Ether/Wrapped.hsnew file+27
@@ -0,0 +1,27 @@
1+{-# LANGUAGE MultiParamTypeClasses #-}
2+{-# LANGUAGE FlexibleInstances #-}
3+{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE UndecidableInstances #-}
5+{-# LANGUAGE ScopedTypeVariables #-}
6+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
7+module Control.Ether.Wrapped where
8+
9+import Data.Proxy (Proxy(Proxy))
10+import Control.Applicative (Alternative)
11+import Control.Monad (MonadPlus)
12+import Control.Monad.Fix (MonadFix)
13+import Control.Monad.IO.Class (MonadIO)
14+import Control.Monad.Ether.Reader
15+
16+import qualified Control.Monad.Reader as Class
17+
18+newtype WrappedEther tag m a = WrapEther { unwrapEther :: m a }
19+ deriving ( Functor, Applicative, Alternative, Monad, MonadPlus
20+ , MonadFix, MonadIO )
21+
22+instance MonadEtherReader tag r m => Class.MonadReader r (WrappedEther tag m) where
23+ ask = WrapEther $ etherAsk (Proxy :: Proxy tag)
24+ local f = WrapEther . etherLocal (Proxy :: Proxy tag) f . unwrapEther
25+
26+ethered :: proxy tag -> WrappedEther tag m a -> m a
27+ethered _proxy = unwrapEther
src/Control/Monad/Ether/Reader.hs+1
@@ -8,6 +8,7 @@
88{-# LANGUAGE TypeOperators #-}
99{-# LANGUAGE FunctionalDependencies #-}
1010{-# LANGUAGE ScopedTypeVariables #-}
11+{-# LANGUAGE RankNTypes #-}
1112{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1213module Control.Monad.Ether.Reader
1314 ( EtherReaderT
test/Regression.hs+10
@@ -6,8 +6,12 @@
66{-# LANGUAGE ScopedTypeVariables #-}
77module Main where
88
9+import Data.Proxy
10+
911import Control.Ether.TH
12+import Control.Ether.Wrapped
1013import Control.Monad.Ether.Reader
14+import Control.Monad.Reader
1115
1216import Test.Tasty
1317import Test.Tasty.QuickCheck
@@ -16,6 +20,9 @@ import Test.QuickCheck.Function
1620ethereal (defaultEtherealReaderConfig "Reader1")
1721ethereal (defaultEtherealReaderConfig "Reader2")
1822
23+r1 :: Proxy TagReader1
24+r1 = Proxy
25+
1926main :: IO ()
2027main = defaultMain suite
2128
@@ -65,3 +72,6 @@ inferCore = local' (succ :: Int -> Int) $ do
6572 n :: Int <- ask'
6673 b <- local' not ask'
6774 return (if b then "" else show n)
75+
76+wrapCore :: MonadEtherReader TagReader1 Int m => m Int
77+wrapCore = ethered r1 ask