Re: [Haskell-cafe] Principal type in Haskell

2006-06-22 Thread Gerrit van den Geest

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



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Principal type in Haskell

2006-06-22 Thread Jerzy Karczmarczuk

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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Principal type in Haskell

2006-06-22 Thread Bulat Ziganshin
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,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Principal type in Haskell

2006-06-22 Thread william kim


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 [EMAIL PROTECTED]
Reply-To: Bulat Ziganshin [EMAIL PROTECTED]
To: william kim [EMAIL PROTECTED]
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,
 Bulatmailto:[EMAIL PROTECTED]



_
Find love on MSN Personals http://personals.msn.com.sg/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe