Multiple functions applied to a single value

Brandon Michael Moore brandon at its.caltech.edu
Tue Dec 9 12:12:02 EST 2003


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



More information about the Haskell-Cafe mailing list