incompatible signatur syntax within instance definition

Christian Maeder maeder at tzi.de
Wed Dec 10 15:08:53 EST 2003


Fergus Henderson wrote:

> Allowing repeated constraints would not be sufficient for that. 

Yes, you're right. A true (but senseless) constraint like "Show Int" is 
rejected as well. (The same applies to "Show a" if "a" is a scoped type 
variable, that is when "a" is monomorph.)

So a function with type "a -> a" in Haskell98 is always polymorphic, 
whereas it may be a monomorphic function in Haskell with glasgow-exts 
(iff "a" is a scoped type variable).

The compatibility problem between Haskell98 and glasgow-exts is thus 
moved to the place where scoped typed variables can be introduced.

Since type annotations of patterns are illegal in Haskell98 the only 
problem was the introduction of scoped type variables through the 
"instance" line. So why was this done (except to shorten notation)?

> Consider the following example:
> 
> 	data MyType a = MkMyType a
> 	class Foo a where
> 		foo :: a -> Int

Since the type "a" usually occurs in every method it is no problem to 
introduce scoped type variables via patterns (that are illegal in 
Haskell98):

         instance Foo (MyType a) where
		foo (_ :: MyType a) = ...
	
> So, to summarize, this particular ghc extension is not a pure extension.
> It can change the legality or even the semantics of Haskell 98 code.
> Allowing repeated constraints won't change that.
> Given that allowing repeated constraints isn't sufficient to solve
> that problem, I don't think it is a good idea to allow them.

I entirely agree with this. The first point would be to make the 
extension "pure". Allowing or disallowing repeated constraints is then a 
mere (unimportant) design option.

> P.S. I note that ghc 5.02.2 enables this extension always, regardless
> of the setting of -fglasgow-exts.  That seems like a bug to me.

I would not worry about bugs in older versions.

Cheers Christian



More information about the Glasgow-haskell-users mailing list