Oleg explained why those work in his last post. It's the exact same logic for each one.<br><br>> f :: a -> a<br>
> f x = x :: a<br><br>We explained that too: it's converted (alpha-converted, but I don't exactly know what 'alpha' refers to. I guess it's phase the type inferer goes through) to:<br><br>f :: forall a. a -> a<br>
f x = x :: forall a1. a1<br><br>On one side, x has type a, on the other, it has type a1. Those are different polymorphic types, yet it's the same variable x hence the incompatibility. So it doesn't type-check.<br>
<br><div class="gmail_quote">2012/1/4 Thiago Negri <span dir="ltr"><<a href="mailto:evohunz@gmail.com">evohunz@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Do not compile:<br>
<div class="im"><br>
f :: a -> a<br>
f x = x :: a<br>
<br>
</div> Couldn't match type `a' with `a1'<br>
<div class="im"> `a' is a rigid type variable bound by<br>
</div> the type signature for f :: a -> a at C:\teste.hs:4:1<br>
`a1' is a rigid type variable bound by<br>
an expression type signature: a1 at C:\teste.hs:4:7<br>
<div class="im"> In the expression: x :: a<br>
</div> In an equation for `f': f x = x :: a<br>
<br>
<br>
Any of these compiles:<br>
<div class="im"><br>
f :: a -> a<br>
f x = undefined :: a<br>
<br>
</div>f :: Num a => a -> a<br>
<div class="im">f x = undefined :: a<br>
<br>
</div>f :: Int -> Int<br>
<div class="im">f x = undefined :: a<br>
<br>
</div>f :: Int -> Int<br>
f x = 3 :: (Num a => a)<br>
<br>
<br>
Can someone explain case by case?<br>
<br>
Thanks,<br>
Thiago.<br>
<br>
2012/1/4 Yves Parès <<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>>:<br>
<div class="HOEnZb"><div class="h5">>> I don't see the point in universally quantifying over types which are<br>
> already present in the environment<br>
><br>
> I think it reduces the indeterminacy you come across when you read your<br>
> program ("where does this type variable come from, btw?")<br>
><br>
><br>
>> So is there anyway to "force" the scoping of variables, so that<br>
>> f :: a -> a<br>
>> f x = x :: a<br>
>> becomes valid?<br>
><br>
> You mean either than compiling with ScopedTypeVariables and adding the<br>
> explicit forall a. on f? I don't think.<br>
><br>
> 2012/1/4 Brandon Allbery <<a href="mailto:allbery.b@gmail.com">allbery.b@gmail.com</a>><br>
><br>
> On Wed, Jan 4, 2012 at 08:41, Yves Parès <<a href="mailto:limestrael@gmail.com">limestrael@gmail.com</a>> wrote:<br>
>><br>
>> Would you try:<br>
>><br>
>> f :: a -> a<br>
>><br>
>> f x = undefined :: a<br>
>><br>
>> And tell me if it works? IMO it doesn't.<br>
><br>
>> It won't<br>
><br>
> Apparently, Yucheng says it does.<br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<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>
</div></div></blockquote></div><br>