[Haskell-beginners] Re: Pointfree expeiments
es at ertes.de
Thu Nov 25 14:15:07 EST 2010
Ozgur Akgun <ozgurakgun at gmail.com> wrote:
> I don't know whether this is related or not, but I have the following
> somewhere in my code:
> -- the following is apparently eqivalent to (\ i -> foo (bar i) i).
> -- pointfree suggests so. i don't understand why.
> (foo =<< bar)
> Is this a similar situation?
Yes, it is. In the reader monad a computation is a function of one
foo :: a -> e -> b
bar :: e -> a
Running such a computation means passing a specific argument 'e' to all
those functions and regarding monadic bindings like normal let bindings.
Let me write this in 'do' syntax, so it gets clearer:
do x <- bar
let x = bar e
in foo x e
I found the reader monad most useful in applicative style:
splits :: [a] -> [([a], [a])]
splits = zip <$> inits <*> tails
nightmare = unsafePerformIO (getWrongWife >>= sex)
More information about the Beginners