<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 5 May 2009, at 11:27, z_axis wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="font-size: 10pt; margin-top: 10px; margin-right: 10px; margin-bottom: 10px; margin-left: 10px; font-family: verdana; "><div><font face="Verdana" size="2"><div>The&nbsp;following&nbsp;code&nbsp;snippets&nbsp;is&nbsp;from&nbsp;xmonad:</div><div></div><div>--&nbsp;Given&nbsp;a&nbsp;window,&nbsp;find&nbsp;the&nbsp;screen&nbsp;it&nbsp;is&nbsp;located&nbsp;on,&nbsp;and&nbsp;compute</div><div>--&nbsp;the&nbsp;geometry&nbsp;of&nbsp;that&nbsp;window&nbsp;wrt.&nbsp;that&nbsp;screen.</div><div>floatLocation&nbsp;::&nbsp;Window&nbsp;-&gt;&nbsp;X&nbsp;(ScreenId,&nbsp;W.RationalRect)</div><div></div><div>--.......</div><div>rr&nbsp;&lt;-&nbsp;snd&nbsp;`fmap`&nbsp;floatLocation&nbsp;w</div><div>&nbsp;</div><div></div><div></div><div>Prelude&gt;&nbsp;:i&nbsp;fmap</div><div>class&nbsp;Functor&nbsp;f&nbsp;where&nbsp;fmap&nbsp;::&nbsp;(a&nbsp;-&gt;&nbsp;b)&nbsp;-&gt;&nbsp;f&nbsp;a&nbsp;-&gt;&nbsp;f&nbsp;b</div><div>&nbsp;</div><div></div><div>It&nbsp;seems&nbsp;it&nbsp;is&nbsp;different&nbsp;from&nbsp;the&nbsp;definition&nbsp;of&nbsp;fmap&nbsp;?</div><div></div><div>sincerely!</div></font></div></div></span></blockquote><br></div><div>As the type signature of fmap explains, it transforms a function. &nbsp;Specifically, it starts with a function (a -&gt; b), and it transforms it to accept an 'a' inside a functor instead of just an a, and return a 'b' inside the same functor instead of just a b. &nbsp;In other words, fmap applies functions inside containers.</div><div><br></div><div>We can see from floatLocation that it returns a pair inside a container - specifically, an X container. &nbsp;Fmap takes snd, and transforms it to work on values inside the X.</div><div><br></div><div>So, snd has type (a,b) -&gt; b, thus fmap snd has type f (a,b) -&gt; f b. &nbsp;In this case, the type it's being applied to is X (ScreenId, W.RationalRect), so f unifies with X, a with ScreenID and b with W.RationalRect. &nbsp;Making snd `fmap` floatLocation w hav the type X W.RationalRect.</div><div><br></div><div>Finally, the bind into rr there takes it out of the X monad all together, getting you a W.RationalRect.</div><div><br></div><div>You may want to read this article which explains some of Haskell's abstraciton mechanisms:</div><div><br></div><div><a href="http://noordering.wordpress.com/2009/03/31/how-you-shouldnt-use-monad/">http://noordering.wordpress.com/2009/03/31/how-you-shouldnt-use-monad/</a></div><div><br></div><div>Bob</div></body></html>