Haskell 98 - Standard Prelude - Floating Class

Karl-Filip Faxen kff@it.kth.se
Thu, 18 Oct 2001 13:49:11 +0200


Jon Fairbairn wrote:
> I agree too, but being able to omit method definitions is
> sometimes useful -- would it be possible to make calls to
> those methods a /static/ error? I suspect this would be hard
> to do.

Yes, quite tricky. The problem is that the class constraints (in an =

inference algorithm or a semantics) only record that some method
was used, not which one. And at the method invocation site it is not
known which instance declaration the method will come from (that's
the point of the Haskell class system, after all).

There are two solutions that I can see: Annotate classes in class =

constraints with exactly which methods were used. Thus for the
expression "x+y" the inference algorithm would record the constraint
"Num{+} a" if x and y has type a in the type environment. Then if
an instance declaration for type Wurble omitted +, that instance =

declaration would not allow us to simplify "Num{+} Wurble".

The second possibility would be to use a separate dataflow analysis
after dictionary conversion to find out if some incomplete dictionary
could flow to a dangerous place. For compilers which use partial =

evaluation to eliminate overloading, this would be particularly
easy. But I think that, given the stylized way dictionaries are
inserted in the code, that this solution is viable in general.