[Haskell-cafe] Re: Reader monad, implicit parameters, or something else altogether?

apfelmus apfelmus at quantentunnel.de
Tue Aug 19 04:17:39 EDT 2008


Bjorn Buckwalter wrote:
> It seems that two options are to use
> either a Reader monad or implicit parameters. Using a Reader monad is
> straight forward enough though it requires writing/converting code
> in/to monadic style and adds some clutter to the formulae. It seems
> implicit parameters could be cleaner but I've seen them referred to as
> everything from evil to "just what you need" and rendering the Reader
> monad obsolete...
> 
> What do you people recommend?

I'd go for applicative functors :)

  instance Applicative ((->) Constants) where
     pure    = const
     f <*> x = \r -> (f r) (x r)

This way, you don't have to use do-syntax and can keep an applicative look-and-feel.

  mu = \AstroData{mu_Earth} -> mu_Earth

  example = pure (*) <*> pure 5 <*> mu

Lifting arithmetic operations and numbers will get annoying with the time, but
that's nothing an  instance Num  can't solve. (If it can't, just hide (*) and
(+) from the prelude and define your own.)



Regards,
apfelmus



More information about the Haskell-Cafe mailing list