On 23-Jul-1998, S.D.Mechveliani <[EMAIL PROTECTED]> wrote:
> This is for Haskell-2:
>
> is there any profound reason to prohibit the constant types in an
> instance context?
For Mercury, we decided to make similar restrictions to Haskell 1.4
regarding instance declarations (at least for the time being).
There were two main reasons, although whether they should
be considered "profound" or important is a matter of opinion.
One reason is that it makes it easier for compilers that support
separate compilation (or dynamic linking) to detect duplicate or
overlapping instance declarations. Detecting overlapping instance
declarations is trivial -- they can't occur. Detecting duplicate
instance declarations is also not too hard -- each instance declaration
can be mapped to a symbol name that includes just the name and arity of
the class and the name and arity of the top-level type constructor for
the instance, and then the system linker can detect duplicate
definitions for this symbol. (Certainly it's possible to build your
own pre-linker that does this check, but that's a bit of a pain. I'd
be interested to know how the Haskell implementations that support
overlapping instance declarations handle this. I guess Hugs handles it
by not supporting separate compilation. How does ghc handle it?)
Another reason is that we have been considering adding some kind
of support for dynamic type class casts -- something analgous to
C++'s `dynamic_cast' or Eiffel's "assignment attempt".
The restrictions on instance contexts would allow an efficient
implementation of such a construct.
There would be at most one instance declaration for each
class and top-level type constructor, and so the table
of instance declarations for each class could simply be
indexed on the top-level type constructor.
But if more general instance contexts were required, then dynamic
type class casts could require a backtracking search at runtime.
--
Fergus Henderson <[EMAIL PROTECTED]> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED] | -- the last words of T. S. Garp.