<div dir="ltr">On Fri, Sep 6, 2013 at 11:04 AM, Johannes Emerich <span dir="ltr"><<a href="mailto:johannes@emerich.de" target="_blank">johannes@emerich.de</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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></blockquote><div><br></div><div>Coming from another language, where functions aren't first class, you will probably be used to the notion that a function type is somehow different from any other type. You'll need to unlearn that for functional languages: function types are just as "real" as (Integer) is, and if I have a type variable somewhere which doesn't have constraints otherwise preventing it, that type variable can end up being (Integer) or (a -> a) or (Num c => c -> c -> c) or (Maybe [x]) or (Maybe (a -> a)) or any other (rank-1, i.e. no internal "forall"s) type.</div>
<div><br></div><div>(id) has the type (a -> a); in the use mentioned in the first quoted paragraph, this has unified (a) with (b -> b) to produce (id :: (b -> b) -> (b -> b)) in order for the whole expression to be typeable. In your second example, you don't have polymorphism "where it's needed" so it can't infer a type that will work.</div>
<div><br></div></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a> <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div>
<div>unix, openafs, kerberos, infrastructure, xmonad <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>