Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
- {-# LANGUAGE ScopedTypeVariables #-}
- import Control.Monad (void)
- newtype AppEnv a = AppEnv (ReaderT () (StateT () IO) a) -- pretend the () are useful types
- deriving (Functor, Applicative, Monad)
- instance MsgsRead AppEnv where
- readMsgPayloads = return [] -- implementation omitted
- instance MsgsWrite AppEnv where
- writeMsgs _ = return () -- implementation omitted
- runAppEnv :: AppEnv () -> IO ()
- runAppEnv (AppEnv appEnv) = evalStateT (runReaderT appEnv ()) ()
- f1 :: forall m. MsgsRead m => m ()
- f1 = void (readMsgPayloads :: m [FooMsgPayload])
- f2 :: MsgsWrite m => m ()
- f2 = writeMsgs [initMsg ZzzMsgA]
- f3 :: forall m. (MsgsRead m, MsgsWrite m) => m ()
- f3 = do
- void (readMsgPayloads :: m [BarMsgPayload])
- writeMsgs [initMsg ZzzMsgC]
- main :: IO ()
- main = runAppEnv $ f1 >> f2 >> f3 -- pretend this is doing something useful
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement