[mercury-users] Extending a structure data type in Mercury

Gregory D. Weber gdweber at indiana.edu
Sun Jun 5 05:52:30 AEST 2005


I want to "extend" a structure type by adding fields, like this:

:- type prule ---> prule(key, class, ftable, conds).
:- type cn2rule == prule.
:- type icnrule ---> icnrule(key, class, ftable, conds, info).

But want icnrule to be considered a subtype of prule,
also as a subtype of cn2rule, so that procedures developed for prules 
and cn2rules will also work for icnrules.

I've found a solution, but I'm wondering if there's a better way.
I add an extra field of variable type to the prule type,
and then instantiate it in different ways to make different kinds of rules:

:- type prule(I) ---> prule(key, class, ftable, conds, I).

:- type cn2rule_info == {}. % empty tuple
:- type cn2rule == prule(cn2rule_info).

:- type icnrule_info == {ftable}.
:- type icnrule == prule(icnrule_info).

One complication of this approach is that, to use a cn2rule as an
icnrule, I have to replace an {} with an {ftable}, and vice-versa.

-- 
Gregory D. Weber             http://mypage.iu.edu/~gdweber/
                             Telephone (765) 973-8420
Associate Professor of Computer Science; Chair, Informatics Committee
Indiana University East
2325 Chester Boulevard, Richmond, Indiana 47374-1289, U.S.A.
----
Plain text is the document format that maximizes readability and
minimizes hassle and hazard.  It is the format of the official documents
defining Internet protocols (http://www.rfc-editor.org/).
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list