<div class="gmail_quote">2008/12/26 Oscar Picasso <span dir="ltr"><<a href="mailto:oscarpicasso@gmail.com">oscarpicasso@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi,<br><br>I can write:<br>*Main> let yes = not . not<br>*Main> :t yes<br>yes :: Bool -> Bool<br><br>But not:<br>*Main> let isNotEqual = not . (==)</blockquote><div><br></div><div>The definition of (.):</div><div>
<br></div><div>f . g = \x -> f (g x)</div><div><br></div><div>So:</div><div><br></div><div>not . (==) = \x -> not ((==) x)</div><div><br></div><div>But (==) x is a function (of type a -> Bool, which returns whether its argument is equal to x), not a Bool as not is expecting.</div>
<div><br></div><div>Composition like that usually only works for single argument functions. It gets uglier quickly for multi arg functions:</div><div><br></div><div>isNotEqual = (not .) . (==)</div><div><br></div><div>You can define your own operator to help:</div>
<div><br></div><div>(.:) = (.) . (.)</div><div><br></div><div>Which is a bit of silly definition. I typically don't like pointfree style for any but the most transparent of uses, so in real life (tm), I'd probably write:</div>
<div><br></div><div>(f .: g) x y = f (g x y)</div><div><br></div><div>But be prepared for others to disagree with me.</div><div><br></div><div>Luke</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><br><interactive>:1:23:<br> Couldn't match expected type `Bool'<br>
against inferred type `a -> Bool'<br> Probable cause: `==' is applied to too few arguments<br> In the second argument of `(.)', namely `(==)'<br> In the expression: not . (==)<br><br>
Why?<br><font color="#888888"><br>Oscar<br><br>
</font><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br>