
Do not compile:
f :: a -> a
f x = x :: a
Couldn't match type `a' with `a1'
`a' is a rigid type variable bound by
the type signature for f :: a -> a at C:\teste.hs:4:1
`a1' is a rigid type variable bound by
an expression type signature: a1 at C:\teste.hs:4:7
In the expression: x :: a
In an equation for `f': f x = x :: a
Any of these compiles:
f :: a -> a
f x = undefined :: a
f :: Num a => a -> a
f x = undefined :: a
f :: Int -> Int
f x = undefined :: a
f :: Int -> Int
f x = 3 :: (Num a => a)
Can someone explain case by case?
Thanks,
Thiago.
2012/1/4 Yves Parès
I don't see the point in universally quantifying over types which are already present in the environment
I think it reduces the indeterminacy you come across when you read your program ("where does this type variable come from, btw?")
So is there anyway to "force" the scoping of variables, so that f :: a -> a f x = x :: a becomes valid?
You mean either than compiling with ScopedTypeVariables and adding the explicit forall a. on f? I don't think.
2012/1/4 Brandon Allbery
On Wed, Jan 4, 2012 at 08:41, Yves Parès
wrote: Would you try:
f :: a -> a
f x = undefined :: a
And tell me if it works? IMO it doesn't.
It won't
Apparently, Yucheng says it does.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe