Skip to content

Commit cad092e

Browse files
switched to Lifting* convention
1 parent 4f3d5d8 commit cad092e

File tree

4 files changed

+22
-43
lines changed

4 files changed

+22
-43
lines changed

Control/Monad/Bypass.hs

Lines changed: 0 additions & 40 deletions
This file was deleted.

Control/Monad/Reader.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ module Control.Monad.Reader (
4040
-- * MonadReader class
4141
MonadReader.MonadReader(..),
4242
MonadReader.asks,
43+
-- * Lifting helper type
44+
MonadReader.LiftingReader,
4345
-- * The Reader monad
4446
Reader,
4547
runReader,

Control/Monad/Reader/Class.hs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
{-# LANGUAGE Safe #-}
21
{-# LANGUAGE FlexibleInstances #-}
32
{-# LANGUAGE FunctionalDependencies #-}
43
{-# LANGUAGE MultiParamTypeClasses #-}
54
-- Search for UndecidableInstances to see why this is needed
65
{-# LANGUAGE UndecidableInstances #-}
6+
{-# LANGUAGE StandaloneKindSignatures #-}
7+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8+
{-# LANGUAGE Trustworthy #-}
79
-- Needed because the CPSed versions of Writer and State are secretly State
810
-- wrappers, which don't force such constraints, even though they should legally
911
-- be there.
@@ -48,6 +50,7 @@ than using the 'Control.Monad.State.State' monad.
4850
module Control.Monad.Reader.Class (
4951
MonadReader(..),
5052
asks,
53+
LiftingReader(..),
5154
) where
5255

5356
import qualified Control.Monad.Trans.Cont as Cont
@@ -68,7 +71,8 @@ import qualified Control.Monad.Trans.Accum as Accum
6871
import Control.Monad.Trans.Select (SelectT (SelectT), runSelectT)
6972
import qualified Control.Monad.Trans.RWS.CPS as CPSRWS
7073
import qualified Control.Monad.Trans.Writer.CPS as CPS
71-
import Control.Monad.Trans.Class (lift)
74+
import Control.Monad.Trans.Class (MonadTrans(lift))
75+
import Data.Kind (Type)
7276

7377
-- ----------------------------------------------------------------------------
7478
-- class MonadReader
@@ -202,3 +206,17 @@ instance
202206
r <- ask
203207
local f (runSelectT m (local (const r) . c))
204208
reader = lift . reader
209+
210+
type LiftingReader :: ((Type -> Type) -> Type -> Type) -> (Type -> Type) -> Type -> Type
211+
newtype LiftingReader t m a = LiftingReader (t m a)
212+
deriving (Functor, Applicative, Monad, MonadTrans)
213+
214+
instance MonadReader r m => MonadReader r (LiftingReader (ReaderT r') m) where
215+
ask = lift ask
216+
local f (LiftingReader (ReaderT.ReaderT x)) = LiftingReader . ReaderT.ReaderT $ local f . x
217+
reader = lift . reader
218+
219+
instance (MonadReader r m, Monoid w) => MonadReader r (LiftingReader (LazyRWS.RWST r' w s) m) where
220+
ask = lift ask
221+
local f (LiftingReader (LazyRWS.RWST x)) = LiftingReader . LazyRWS.RWST $ \r s -> local f $ x r s
222+
reader = lift . reader

mtl.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Library
3232
exposed-modules:
3333
Control.Monad.Cont
3434
Control.Monad.Cont.Class
35-
Control.Monad.Bypass
3635
Control.Monad.Error.Class
3736
Control.Monad.Except
3837
Control.Monad.Identity

0 commit comments

Comments
 (0)