[m-dev.] for review: improvements for record syntax

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Dec 6 12:09:51 AEDT 2000


On 06-Dec-2000, schachte at cs.mu.OZ.AU <schachte at cs.mu.OZ.AU> wrote:
> is it more natural to
> write functions to, say, index and update an array as
> 
> 	:- func elem(array, index) = int.
> 	:- func 'elem :='(array, index, int) = array.
> 
> or
> 
> 	:- func elem(index, array) = int.
> 	:- func 'elem :='(index, array, int) = array.
> 
> I guess the former look a bit better to me,

Richard O'Keefe's guidelines about argument ordering, which are
explained in his book The Craft of Prolog, say that collection types
such as array should precede indexes.  The reason for this is to be
consistent with the suggested ordering for in/out mode arguments,
namely that in mode arguments should precede out mode arguments.
The point here is that you might want to define a mode of `elem'
that nondeterministically produces all the elements of the
array:

	:- func elem(array, index) = int.
	:- mode elem(in, in) = out is det.
	:- mode elem(in, out) = out is nondet.

If you use the other argument ordering, then this mode has to be

	:- func elem(index, array) = int.
	:- mode elem(in, in) = out is det.
	:- mode elem(out, in) = out is nondet.

which would violate the normal in/out mode argument ordering.

Note that it's not possible to have a mode in which you produce the
array given the index and the element.

So I agree with you, the `array, index' ordering looks better.

P.S. Will the new field access syntax allow examples like that?
E.g. can I write `some [Index] (Array ^ elem(Index) > Index)' 
and have it `elem' nondeterministically produce the corresponding
indices and elements of the array?

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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