[m-dev.] Re: For review: changes to graph.m

Peter Schachte pets at cs.mu.oz.au
Thu Jun 5 16:15:40 AEST 1997


On Thu, 5 Jun 1997, Fergus Henderson wrote:

> > > 	let
> > > 		map0 = map_init
> > > 		map1 = map_insert map0 "foo" 42 ....
>
> Actually that's not correct.  Given a type, it will figure out which
> instance declaration to use, but in this example it has to figure out
> the type from the instance declarations, and it won't do that.

This is really a shame.  Maybe I'm looking for something more like classes
than type classes, where there is an is-a relation between subclasses and
superclasses.  When you say that the operation you're implementing will
work for class X, then you're promising that it'll work for all subclasses
of X, too.  In that context, it makes perfect sense to choose the "best"
(however we define that) class that provides all the needed operations. 

> (This is sensible, given how type classes work: in general, the
> different types might have different semantics, not just different
> efficiency, and so it shouldn't guess for you...)

This seems strange to me.  If I have a type class comparable which
promises a predicate less/2, it really should be promising a common
semantics for that predicate.  I would expect less/2 to be irreflexive,
asymmetric, and transitive, for example.  Someone might be tempted to put
the set type in the comparable class, and use subset as the implementation
of less, but I think that would be wrong, because exactly one of less(X,Y)
or less(Y,X) or X=Y should always hold.  That's part of what I mean by
comparable. 

Given this argument, and given that a predicate written for a type class
doesn't use operations not promised by that type class, then I'd argue
that different types in a type class must have the same semantics as far
as can be seen from that type class.  Therefore if you specify a type
class rather than a type for the argument of a predicate, then you are
saying that any type in that type class will be acceptable, so /anything/
the compiler chooses should be acceptable. If the compiler has a good
heuristic for choosing, so much the better. 


-Peter Schachte      URL:  http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU     PGP:  finger pets at 128.250.37.150 for key
    [A computer is] like an Old Testament god, with a lot of rules
    and no mercy.  -- Joseph Campbell




More information about the developers mailing list