-
Notifications
You must be signed in to change notification settings - Fork 1
/
TwoReaders.hs
30 lines (24 loc) · 876 Bytes
/
TwoReaders.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Examples.TwoReaders where
import "has-transformers" Control.Monad.Trans.Has.Reader
-- | Our "business logic" program using two 'ReaderT' effects.
-- Note that we use a type signature to help the type checker understand
-- which environment is which.
program ::
(Monad m, HasReader Int m, HasReader Bool m) =>
m (Int, Bool)
program = do
envInt <- ask
envBool <- ask
return (envInt, envBool)
-- | The 'Int' environment we are going to supply
envInt :: Int
envInt = 23
-- | The 'Bool' environment we are going to supply
envBool :: Bool
envBool = True
-- | For documentation, this is the stack that will be handled.
-- (But we don't actually ever use this type alias.)
type Stack a = ReaderT Int (ReaderT Bool IO) a
-- | The 'program' with its environments supplied
handled :: IO (Int, Bool)
handled = program `runReaderT` envInt `runReaderT` envBool