<div dir="ltr">The thing that you might also be missing is that function application binds tightest. Hopefully the parenthesis that Rahul has added help you out there. If not:<div><br></div><div>\w -> f (h w) w<br></div><div><br></div><div>f will be applied to the result of (h r) which yields another function, which is then applied to r</div><div><br></div><div>that is</div><div><br></div><div>\w -></div><div>let x = h w</div><div>g = f x</div><div>in g w</div><div><br></div><div>would yield exactly the same result. I apologise for the indentation, I need a better mail client.</div><div><br></div><div>Ben</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, 21 Feb 2017 at 14:34 Rahul Muttineni <<a href="mailto:rahulmutt@gmail.com">rahulmutt@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hi Olumide,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Let the types help you out.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The Monad typeclass (omitting the superclass constraints):</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">class Monad m where</div><div class="gmail_msg"> return :: a -> m a</div><div class="gmail_msg"> (>>=) :: m a -> (a -> m b) -> m b</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Write out the specialised type signatures for (->) r:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">{-# LANGUAGE InstanceSigs #-}</div><div class="gmail_msg">-- This extension allows you to specify the type signatures in instance declarations</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">instance Monad ((->) r) where</div></div><div dir="ltr" class="gmail_msg"><div class="gmail_msg"> return :: a -> (r -> a)</div><div class="gmail_msg"> (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b)</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Now we look at how to make some definition of return that type checks. We're given an a and we want to return a function that takes an r and returns an a. Well the only way you can really do this is ignoring the r and returning the value you were given in all cases! Because 'a' can be *anything*, you really don't have much else you can do! Hence:</div><div class="gmail_msg"> </div><div class="gmail_msg"> return :: a -> (r -> a)</div><div class="gmail_msg"> return a = \_ -> a</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Now let's take a look at (>>=). Since this is a bit complicated, let's work backwards from the result type. We want a function that gives us a b given an r and given two functions with types (r -> a) and (a -> (r -> b)). To get a b, we need to use the second function. To use the second function, we must have an a, which we can get from the first function!</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> (>>=) :: (r -> a) -> (a -> (r -> b)) -> (r -> b)</div><div class="gmail_msg"> (>>=) f g = \r -> (g (f r)) r</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Hope that helps!</div><div class="gmail_msg">Rahul</div><div class="gmail_msg"> </div></div><div class="gmail_extra gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Tue, Feb 21, 2017 at 5:04 PM, Olumide <span dir="ltr" class="gmail_msg"><<a href="mailto:50295@web.de" class="gmail_msg" target="_blank">50295@web.de</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="gmail_msg">On 21/02/2017 10:25, Benjamin Edwards wrote:<br class="gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
What is it that you are having difficulty with? Is it "why" this is a<br class="gmail_msg">
good definition? Is it that you don't understand how it works?<br class="gmail_msg">
</blockquote>
<br class="gmail_msg"></span>
I simply can't grok f (h w) w.<br class="gmail_msg">
<br class="gmail_msg">
- Olumide<br class="gmail_msg">
<br class="gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="gmail_msg">
On Tue, 21 Feb 2017 at 10:15 Olumide <<a href="mailto:50295@web.de" class="gmail_msg" target="_blank">50295@web.de</a><br class="gmail_msg"></span><span class="gmail_msg">
<mailto:<a href="mailto:50295@web.de" class="gmail_msg" target="_blank">50295@web.de</a>>> wrote:<br class="gmail_msg">
<br class="gmail_msg">
Hello List,<br class="gmail_msg">
<br class="gmail_msg">
I am having enormous difficulty understanding the definition of the bind<br class="gmail_msg">
operator of ((->) r) as show below and would appreciate help i this<br class="gmail_msg">
regard.<br class="gmail_msg">
<br class="gmail_msg">
instance Monad ((->) r) where<br class="gmail_msg">
return x = \_ -> x<br class="gmail_msg">
h >>= f = \w -> f (h w) w<br class="gmail_msg">
<br class="gmail_msg">
Thanks,<br class="gmail_msg">
<br class="gmail_msg">
- Olumide<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg"></span>
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a> <mailto:<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a>><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><span class="gmail_msg"><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg">
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="gmail_msg">
<br class="gmail_msg">
</span></blockquote><div class="m_770733040903508895HOEnZb gmail_msg"><div class="m_770733040903508895h5 gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg">
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="gmail_msg">
</div></div></blockquote></div><br class="gmail_msg"><br clear="all" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div></div><div class="gmail_extra gmail_msg">-- <br class="gmail_msg"><div class="m_770733040903508895gmail_signature gmail_msg" data-smartmail="gmail_signature">Rahul Muttineni</div>
</div>
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg">
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="gmail_msg">
</blockquote></div>