Oleg explained why those work in his last post. It's the exact same logic for each one.
> f :: a -> a > f x = x :: a 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: f :: forall a. a -> a f x = x :: forall a1. a1 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. 2012/1/4 Thiago Negri <evoh...@gmail.com> > 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 <limestr...@gmail.com>: > >> 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 <allber...@gmail.com> > > > > On Wed, Jan 4, 2012 at 08:41, Yves Parès <limestr...@gmail.com> 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 > > >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe