[m-dev.] record syntax

Thomas Conway conway at cs.mu.OZ.AU
Wed Feb 23 16:17:00 AEDT 2000


Hi

I've just been fiddling with record syntax, and it doesn't quite
do what I want, so I need someone to convince me to do it a *better*
way. ;-)

I have a type:

:- type ppid
	--->	pred(string, string, int, int)
	;	func(string, string, int, int)
	;	comp(string, string, string, string, int, int)
	.

Now, all three functors have four fields corresponding to
module-name, pred/func-name, arity and mode number respectively.
So, I'd like to write:

:- type ppid
	--->	pred(modname::string, name::string, arity::int, modenum::int)
	;	func(modname::string, name::string, arity::int, modenum::int)
	;	comp(typemod::string, typename::string,
			modname::string, name::string, arity::int, modenum::int)
	.

Of course, PPId^typemod and PPId^modname should be semidet, but
I can't think of a good reason why I shouldn't be allowed to reuse
a field name in multiple functors. Especially as I want to. :-)

The code should look something like:

:- func modname(ppid) = string.
modname(pred(X, _, _, _)) = X.
modname(func(X, _, _, _)) = X.
modname(comp(_, _, X, _, _, _)) = X.

There. That wasn't too hard, was it?

Comments?
-- 
 Thomas Conway )O+     Every sword has two edges.
     Mercurian            <conway at cs.mu.oz.au>
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list