[mercury-users] Type inheritance?
fjh at cs.mu.oz.au
Wed Sep 24 12:27:51 AEST 1997
Lee Naish, you wrote:
> In message <199709231225.WAA09248 at mundook.cs.mu.OZ.AU>Fergus wrote:
> >Type classes would however allow us to refine the mode system slightly
> >to avoid the drawback mentioned above regarding mixing mode-based subtypes
> >with polymorphic predicates. The reason that the compiler needs to
> >make conservative assumptions about mode-based subtypes is the existence of
> >std_util__construct (which is used to implemented io__read, etc.).
> >With type classes, we could in the usual case make more precise assumptions,
> >and only use the more conservative assumptions in the case when the
> >polymorphic predicate's argument type was declared to be a member of the
> >`constructable' type-class.
> If I understand this correctly, a possibly better approach would be to
> restrict the types of predicates which are not "really" polymorphic.
Well, your suggested approach is exactly what I had in mind...
so maybe you didn't understand my original description correctly ;-)
I guess I didn't explain it very well.
Probably the word "argument" above is confusing -- I actually meant
"parameter". That is, the type class qualification that we care about
is the one one the predicates formal parameter, not it's actual
argument in any given call.
> Something like:
> <polymorphic declaration> <= <type class for "nice" types>
Yes, for example
:- pred io__read(T, io__state, io__state) <= constructable(T).
Did you really mean "nice"? If anything constructable types are less
nice, because if a predicate is polymorphic on a constructable type,
that doesn't guarantee that the predicate is polymorphic on subtypes of
that type -- i.e. you don't get the usual "free theorems".
> "Real" polymorphic predicates like append (in fact, everything but some
> very low level predicates) wouldn't need this extra condition.
I'm not sure I agree with that description -- `io__read' could be considered
a quite high-level predicate. But yes, append would be just
:- pred append(list(T), list(T), list(T)).
with no type-class constraints, and so the compiler could be sure
that appending lists of subtypes gives a result that is in the
> (I believe the fact
> that polymorphism is "broken" in current version of Mercury is a
> significant flaw).
I agree that it is a flaw. On the other hand, not supporting
io__read or some equivalent would be a much worse flaw, IMHO.
(And of course the current flaw is one that will soon be remedied,
as soon as we have type classes ;-)
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 126.96.36.199 | -- the last words of T. S. Garp.
More information about the users