[Haskell-cafe] Closed Classes

MR K P SCHUPKE k.schupke at imperial.ac.uk
Thu Aug 12 13:37:20 EDT 2004


Okay (thanks to Simon PJ) - the problem appears to be
that applying the improvement rules could result in a function
being exported with an incorrect type signature (if a later
module defines additional instances):

	module X (f,g) where

	class A a where
	   f :: a -> a
	instance A Int where
	   f = id

	g x = f x

After appling improvement 'g's type would be "g::Int -> Int", however
if we now do:

	module Y where

	import X

	instance A Float where
	   f x = x + 1.0

	h x = g x

Then after the type sig exported for 'g' is wrong ... 

So my question is now:

What if we don't improve the types of 'f' at all and leave it at
its most general: "g :: A a => a -> a", and instead wait until
we are tring to resolve overloading to apply improvement.

IE at some point we must decide which dictionary to pass in, to the
top level function (with a constraint "A a =>") what happens if
we defer improvement till this point?

Surely it must be safe to assume a closed class at the top level?

	Keean.


More information about the Haskell-Cafe mailing list