1module Control.Monad.Reader
4import Control.Monad.Identity
5import Control.Monad.Trans
9||| A monad representing a computation that runs in an immutable context
10class Monad m => MonadReader r (m : Type -> Type) where
11 ||| Return the context
13 ||| Temprorarily modify the input and run an action in the new context
14 local : (r -> r) -> m a -> m a
16||| The transformer on which the Reader monad is based
17record ReaderT : Type -> (Type -> Type) -> Type -> Type where
18 RD : {m : Type -> Type} ->
19 (runReaderT : r -> m a) -> ReaderT r m a
21||| Create a ReaderT with an empty context
22liftReaderT : {m : Type -> Type} -> m a -> ReaderT r m a
23liftReaderT m = RD $ const m
25instance Functor f => Functor (ReaderT r f) where
26 map f (RD g) = RD $ (map f) . g
28instance Applicative m => Applicative (ReaderT r m) where
29 pure = liftReaderT . pure
30 (RD f) <*> (RD v) = RD $ \r => f r <*> v r
32instance Alternative m => Alternative (ReaderT r m) where
33 empty = liftReaderT empty
34 (RD m) <|> (RD n) = RD $ \r => m r <|> n r
36instance Monad m => Monad (ReaderT r m) where
37 (RD f) >>= k = RD $ \r => do a <- f r
41instance Monad m => MonadReader r (ReaderT r m) where
43 local f (RD m) = RD $ m . f
45instance MonadTrans (ReaderT r) where
48||| Evaluate a function in the context of a Reader monad
49asks : MonadReader r m => (r -> a) -> m a
53||| The reader monad. See MonadReader
54Reader : Type -> Type -> Type
55Reader r a = ReaderT r Identity a
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list