[mercury-users] Extending a structure data type in Mercury
Gregory D. Weber
gdweber at indiana.edu
Wed Jul 6 10:36:42 AEST 2005
(Thanks for your response; I've been away; it's nice to be getting back to Mercury.)
I did consider using typeclasses. If I understand correctly,
typeclasses are like interfaces in Java, so I would have to
declare a type class with some methods, then define
instances ("classes"?) which implement those methods.
I can't have one typeclass be a subclass of another
and inherit methods from it, can I?
So if I were to do this with type classes, I would need to think
of prules, etc., as abstract data types; the type class
would declare methods like prule_key, prule_class, prule_ftable, prule_conds,
and the instances cn2rule and icnrule would each have to define implementations
of those methods. Correct?
Greg
Ralph Becket <rafe at cs.mu.OZ.AU> writes:
> Gregory D. Weber, Saturday, 4 June 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.
>
> Hmm. I think you might find it easiest to do this sort of thing using
> type classes. Would that work?
>
> -- Ralph
--
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