@@ -1,20 +1,25 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE TemplateHaskell #-}
6{-# LANGUAGE TemplateHaskell #-}
7+{-# LANGUAGE TypeFamilies #-}
8+{-# LANGUAGE UndecidableInstances #-}
11-------------------------------------------------------------------------------
14-------------------------------------------------------------------------------
12−import Control.Applicative as A
15+import Control.Applicative as A
13−import Control.Lens hiding ((.=))
16+import Control.Lens hiding ((.=))
17+import Control.Monad.Base
14import Control.Monad.Reader
18import Control.Monad.Reader
19+import Control.Monad.Trans.Control
15import Data.Aeson
20import Data.Aeson
16−import Data.Monoid as M
21+import Data.Monoid as M
17−import System.IO (stdout)
22+import System.IO (stdout)
18-------------------------------------------------------------------------------
23-------------------------------------------------------------------------------
19import Katip
24import Katip
20-------------------------------------------------------------------------------
25-------------------------------------------------------------------------------
@@ -86,9 +91,28 @@ confrabulateWidgets = return ()
86-------------------------------------------------------------------------------
91-------------------------------------------------------------------------------
87newtype MyStack m a = MyStack {
92newtype MyStack m a = MyStack {
88 unStack :: ReaderT MyState m a
93 unStack :: ReaderT MyState m a
89− } deriving (MonadReader MyState, Functor, A.Applicative, Monad, MonadIO)
94+ } deriving (MonadReader MyState, Functor, A.Applicative, Monad, MonadIO, MonadTrans)
97+-- MonadBase, MonadTransControl, and MonadBaseControl aren't strictly
98+-- needed for this example, but they are commonly required and
99+-- MonadTransControl/MonadBaseControl are a pain to implement, so I've
100+-- included them. Note that KatipT and KatipContextT already do this work for you.
101+instance MonadBase b m => MonadBase b (MyStack m) where
102+ liftBase = liftBaseDefault
105+instance MonadTransControl MyStack where
106+ type StT MyStack a = StT (ReaderT Int) a
107+ liftWith = defaultLiftWith MyStack unStack
108+ restoreT = defaultRestoreT MyStack
111+instance MonadBaseControl b m => MonadBaseControl b (MyStack m) where
112+ type StM (MyStack m) a = ComposeSt MyStack m a
113+ liftBaseWith = defaultLiftBaseWith
114+ restoreM = defaultRestoreM
92instance (MonadIO m) => Katip (MyStack m) where
116instance (MonadIO m) => Katip (MyStack m) where
93 getLogEnv = view msLogEnv
117 getLogEnv = view msLogEnv