[mercury-users] Type inheritance?

Lee Naish lee at cs.mu.oz.au
Wed Sep 24 13:10:27 AEST 1997

In message <Pine.GSO.3.95.970924101606.14472A-100000 at cat.cs.mu.OZ.AU>pets wrote:
>A `:- supertype' declaration, or better yet a syntax for mixing constructors
>and type names on the right side of a type declaration, would be much easier
>to use, and I think much more natural.  I guess it would be much harder for
>you to implement in the manner you have in mind, though.

Another possibility is to use something like the undscriminated union
syntax supported by NUDE:

:- type ut = foo + bar.

You could use (for example) ++ instead of + and impose the restriction
that the constructors in foo and bar are disjoint.  Even more flexible
is that the constructors are "compatible", so c(t1) and c(t2) are allowed
in foo and bar, respectively, iff t1 = t2.  Basically, ut is the result
of merging the types foo and bar, and you impose {the minimal}
restrictions to avoid overloading of constructors within the type (you
could even allow t1 and t2 to be different and recursively take their
union, though I'm not sure its a good idea).  You might also want to avoid
unions of integers and lists, for example, even though there is no ambiguity.

The disadvantage of this and the `:- supertype' approach is that if you
are thinking at an implementation level, you need to know all the types
in the program in order to know how many tags are needed for a given
type (assuming current implementation techniques).  The implementation
of your carefully designed 234 tree data type can be affected by some far
off declaration which includes it in union.  From a high level its fine
of course.


More information about the users mailing list