
Hi All, I am confused by the notion of principal type in Haskell with type classes. Consider a simple example: f x y = [x] == [y] GHCi yields type f :: (Eq [a]) => a -> a -> Bool. But according to the paper "Type classes: an exploration of the design space", predicate Eq [a] should be reduced to Eq a. Is this reduction performed here? What should be the principal type of f? Thanks. william _________________________________________________________________ Get an advanced look at the new version of MSN Messenger. http://messenger.msn.com.sg/Beta/Default.aspx

According to Haskell 98 the principal type of f should be: f :: (Eq a) => a -> a -> Bool. GHC does only perform context-reduction using instance-declarations if there are no type-variables in the type. Because the type in this function is [a], ghc doesn't perform context-reduction. Ghc chooses this strategy because of extensions like overlapping instances, there remains more information in the type of a function to select an instance. For some reason GHC also applies this strategy if one turns of the extensions. Grt william kim wrote:
Hi All,
I am confused by the notion of principal type in Haskell with type classes. Consider a simple example:
f x y = [x] == [y]
GHCi yields type f :: (Eq [a]) => a -> a -> Bool.
But according to the paper "Type classes: an exploration of the design space", predicate Eq [a] should be reduced to Eq a. Is this reduction performed here? What should be the principal type of f?
Thanks.
william
_________________________________________________________________ Get an advanced look at the new version of MSN Messenger. http://messenger.msn.com.sg/Beta/Default.aspx
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

william kim wrote:
I am confused by the notion of principal type in Haskell with type classes. Consider a simple example:
f x y = [x] == [y]
GHCi yields type f :: (Eq [a]) => a -> a -> Bool.
But according to the paper "Type classes: an exploration of the design space", predicate Eq [a] should be reduced to Eq a.
Does it mean that nobody is entitled to override the standard instance, and, say, declare: instance Eq [a] where x==y = length x == length y ? Jerzy Karczmarczuk

Hello william, Thursday, June 22, 2006, 1:22:32 PM, you wrote:
GHCi yields type f :: (Eq [a]) => a -> a -> Bool.
But according to the paper "Type classes: an exploration of the design space", predicate Eq [a] should be reduced to Eq a. Is this reduction performed here? What should be the principal type of f?
Ghc, unlike H98, supports instances like this: instance Eq [MyType] where a==b = True so this extension to type inference allows to use such instance even if MyType is not in Eq class -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Thanks. Do I therefore able to conclude that none of the reductions using instance declarations are not performed because of potential overlapping instances? william
From: Bulat Ziganshin
Reply-To: Bulat Ziganshin To: "william kim" CC: haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Principal type in Haskell Date: Thu, 22 Jun 2006 14:28:14 +0400 Hello william,
Thursday, June 22, 2006, 1:22:32 PM, you wrote:
GHCi yields type f :: (Eq [a]) => a -> a -> Bool.
But according to the paper "Type classes: an exploration of the design space", predicate Eq [a] should be reduced to Eq a. Is this reduction performed here? What should be the principal type of f?
Ghc, unlike H98, supports instances like this:
instance Eq [MyType] where a==b = True
so this extension to type inference allows to use such instance even if MyType is not in Eq class
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_________________________________________________________________ Find love on MSN Personals http://personals.msn.com.sg/

Hello william, Thursday, June 22, 2006, 9:12:44 PM, you wrote: sorry, i don't even understood your question
Thanks. Do I therefore able to conclude that none of the reductions using instance declarations are not performed because of potential overlapping instances?
Ghc, unlike H98, supports instances like this:
instance Eq [MyType] where a==b = True
so this extension to type inference allows to use such instance even if MyType is not in Eq class
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (4)
-
Bulat Ziganshin
-
Gerrit van den Geest
-
Jerzy Karczmarczuk
-
william kim