[m-dev.] record syntax

David Overton dmo at ender.cs.mu.oz.au
Thu Feb 24 10:42:15 AEDT 2000


On Thu, Feb 24, 2000 at 08:50:16AM +1100, Thomas Conway wrote:
> On Wed, Feb 23, 2000 at 04:55:14PM EST, David Overton wrote:
> > Here's one way you could achieve this interface to the ppid type with
> > the current system, with just a bit more typing and slightly less
> > efficiency:
> > 
> > 	:- type ppid
> > 		--->	ppid(
> > 				ppid_2 :: ppid_2,
> > 				modname :: string,
> > 				predname :: string,
> > 				arity :: int,
> > 				modenum :: int
> > 			).
> > 
> > 	:- type ppid_2
> > 		--->	pred
> > 		;	func
> > 		;	comp(typemod_2::string, typename_2::string).
> 
> I considered this and it isn't feasible because it uses an extra
> word (assuming we have at least two tag bits on pointers). I'm
> allocating a few million of these, and lots of other structures besides,
> so every word counts.

Ok, how about this:

:- type ppid
	--->	pred(
			pred_modname :: string,
			pred_name :: string,
			pred_arity :: int,
			pred_modenum :: int
		)
	;	func(
			func_modname :: string,
			func_name :: string,
			func_arity :: int,
			func_modenum :: int
		)
	;	comp(
			typemod :: string,
			typename :: string,
			comp_modname :: string,
			comp_name :: string,
			comp_arity :: int,
			comp_modenum :: int
		).

:- func modname(ppid) = string.
:- func 'modname:='(ppid, string) = ppid.

modname(PPID) = PPID^pred_modname.
modname(PPID) = PPID^func_modname.
modname(PPID) = PPID^comp_modname.

'modname:='(PPID, ModName) = PPID^pred_modname := ModName.
'modname:='(PPID, ModName) = PPID^func_modname := ModName.
'modname:='(PPID, ModName) = PPID^comp_modname := ModName.

... etc ...

-- 
David Overton       Department of Computer Science & Software Engineering
PhD Student         The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159     http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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