
9 Dec
2003
9 Dec
'03
3:12 p.m.
Control.Monad.Reader defines instances of Monad and MonadReader for ((->) r). Strangely enough, the documentation claims the Monad instance comes from Control.Monad, which is untrue. Here's the relevant chunk of the file. It looks like you came up with exactly the same code (modulo names). -- ---------------------------------------------------------------------------- -- The partially applied function type is a simple reader monad instance Functor ((->) r) where fmap = (.) instance Monad ((->) r) where return = const m >>= k = \r -> k (m r) r instance MonadFix ((->) r) where mfix f = \r -> let a = f a r in a instance MonadReader r ((->) r) where ask = id local f m = m . f Brandon