<div dir="ltr"><div><div><div>The observation that this only applies to functions with a polymorphic return type is key.<br><br></div> id :: a -> a<br><br></div>This can be instantiated at<br></div><div><br> id' :: (a->b) -> (a->b)<br>
</div><div><div><div><div> id' :: (a->b) -> a -> b -- these are the same<br><br></div><div>What this means is that id is a function with arity-2 whenever the first argument is arity-1, and generally id is a function of arity x+1 where x is the argument arity. Incidentally, this is exactly the same as the ($) operator.<br>
<br></div><div>John L.<br></div><div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 6, 2013 at 10:04 AM, Johannes Emerich <span dir="ltr"><<a href="mailto:johannes@emerich.de" target="_blank">johannes@emerich.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As is well known, any binary function f can be turned into an infix operator by surrounding it with backticks:<br>
<br>
f a b -- prefix application<br>
a `f` b -- infix application<br>
<br>
It is then possible to take left and right sections, i.e. partially applying f:<br>
<br>
(a `f`) -- equivalent to \b -> a `f` b<br>
(`f` b) -- equivalent to \a -> a `f` b<br>
<br>
This extends relatively naturally to functions of arity greater than two, where usage of a function in infix notation produces a binary operator that returns a function of arity n-2.<br>
<br>
Weirdly, however, infix notation can also be used for unary functions with polymorphic types, as the following ghci session shows:<br>
<br>
Prelude> :t (`id` 1)<br>
(`id` 1) :: Num a => (a -> t) -> t<br>
Prelude> (`id` 1) (\y -> show y ++ ".what")<br>
"1.what"<br>
<br>
Desugaring of an equivalent source file shows that id is applied to the anonymous function, which is then applied to 1.<br>
<br>
The following example of a function that is not polymorphic in its return type behaves closer to what I would have expected: It does not work.<br>
<br>
Prelude> let z = (\y -> True) :: a -> Bool<br>
Prelude> :t (`z` True)<br>
<br>
<interactive>:1:2:<br>
The operator `z' takes two arguments,<br>
but its type `a0 -> Bool' has only one<br>
In the expression: (`z` True)<br>
<br>
What is the purpose/reason for this behaviour?<br>
<br>
Thank you,<br>
--Johannes<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>
</blockquote></div><br></div></div></div></div></div></div></div></div>