On Sun, Dec 21, 2008 at 10:28 AM, Maurício <briqueabra...@yahoo.com> wrote: > Hi, > > Why isn't the last line of this code allowed? > > f :: (TestClass a) => a -> Integer > f = const 1 > a = (f,f) > g = fst a > > The only thing I can think about is monomorphism > restriction, but it's allowed (or even the third > line would not be accepted). Is there something > I could read to understand that? > > Thanks, > Maurício > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe >
The monomorphism restriction refuses to accept the definition of a. However, even if we turn the monomorphism restriction off there is still a problem. > {-# LANGUAGE NoMonomorphismRestriction #-} > > f :: (TestClass a) => a -> Integer > f = const 1 > a = (f,f) > g = fst a In this case, the definition of a is accepted, but not the definition of g. The reason is that a has type a :: (TestClass a, TestClass b) => (a,b) and then when we take 'fst' of this value (as in g) we get g :: (TestClass a, TestClass b) => a which is an ambiguous type, since there is no way to tell the compiler what 'b' is when running g. Cheers, Reiner _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe