Missing something with Reader monad - passing the damn thing around everywhere
Posted
by
Richard Huxton
on Stack Overflow
See other posts from Stack Overflow
or by Richard Huxton
Published on 2012-06-27T12:34:39Z
Indexed on
2012/06/27
15:16 UTC
Read the original article
Hit count: 194
Learning Haskell, managing syntax, have a rough grasp of what monads etc are about but I'm clearly missing something.
In main
I can read my config file, and supply it as runReader (somefunc) myEnv
just fine. But somefunc
doesn't need access to the myEnv
the reader supplies, nor do the next couple in the chain. The function that needs something from myEnv is a tiny leaf function.
So - how do I get access to the environment in a function without tagging all the intervening functions as (Reader Env)
? That can't be right because otherwise you'd just pass myEnv around in the first place. And passing unused parameters through multiple levels of functions is just ugly (isn't it?).
There are plenty of examples I can find on the net but they all seem to have only one level between runReader and accessing the environment.
© Stack Overflow or respective owner