Type inheritance?
John Griffith
griffith at sfs.nphil.uni-tuebingen.de
Sun Sep 21 21:18:22 AEST 1997
Just started trying to write a small program in mercury. Getting the
hang of it, but I'm not quite clear on the type system.
Is there any way to get inheritance of types?
For example, I have some type declarations like:
(1)
:- type ft
---> bot
; typ(typ)
; feat(string,ft)
; and(ft,ft)
; or(ft,ft)
; not(ft).
:- type typ
---> top
; a
; b.
which is fine, except I'd really like to get rid of the typ/1
constructor in the declaration for ft. Essentially I want to write
something like this instead:
(2)
:- type ft
---> bot
; { typ }
; feat(string,ft)
; and(ft,ft)
; or(ft,ft)
; not(ft).
:- type typ
---> top
; a
; b.
and have it be equivalent to having written:
(3)
:- type ft
---> bot
; top
; a
; b
; feat(string,ft)
; and(ft,ft)
; or(ft,ft)
; not(ft).
I want to define predicates with arguments of type typ but call them
with arguments of type ft.
Is this possible? If not, then is there a cost associated with the
constructors or do they get "compiled away"? In other words, is there
an efficiency difference between (1) and (3)?
--
John Griffith
Seminar fuer Sprachwissenschaft, Universitaet Tuebingen
email: <URL:mailto:griffith at sfs.nphil.uni-tuebingen.de>
www: <URL:http://www.sfs.nphil.uni-tuebingen.de/~griffith>
More information about the users
mailing list