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

David Glen JEFFERY dgj at cs.mu.oz.au
Thu Jun 5 17:56:36 AEST 1997


> 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.

One of the classic examples of the problems caused by overlapping instances is
something like:

typeclass Showable a where
	show::a->String

instance (Showable a) => Showable [a] where
	show = convert_to_comma_separated_list...

instance Showable [Char] where
	show = convert_char_list_to_string_directly...

In this example, there are two instances which have different semantics. They
are also overlapping, and using the wrong one would be a Bad Thing(TM).

Here's a particulary nasty one, using the declarations above:

foo::(Showable a) => Int -> a -> String
foo num thing = show (repeat num thing)

In this case, the (probable) desired effect would be to use the more specific
version of show when a Char is passed to foo. However, at compile time, we
would be forced to use the first instance declaration, so the more general
version of show would be used.

Ulch.


love and cuddles,
dgj
-- 



This .sig deliberately left blank






More information about the developers mailing list