[mercury-users] Another indexing proposal (was mercury website (was Suggestion: new operator))

Peter Schachte schachte at cs.mu.OZ.AU
Sat Oct 21 11:59:27 AEDT 2000


On Sat, Oct 21, 2000 at 01:46:42AM +1100, Fergus Henderson wrote:
> On 20-Oct-2000, schachte at cs.mu.OZ.AU <schachte at cs.mu.OZ.AU> wrote:
> > For concreteness, here's a simple proposal.  Like the "where equality
> > is ..." suffix on type declarations, Mercury would allow "where
> > application is...".  For example:
> > 
> > 	:- type map(K,V) ---> ...
> > 		where application is map__lookup.
> > 
> > 	:- type string ...
> > 		where application is string__application.
> > 
> > 	% select a single character of a string
> > 	:- func string__application(string::in, int::in) = char is det.
> > 
> > 	% take a substring specified by start and end character positions
> > 	:- func string__application(string::in, int::in, int::in) = string
> > 	        is det.
> 
> If we were going to do allow juxtaposition to denote things other
> than calls, I would use a different syntax: just define '' as a
> function (or predicate) name.  For example

Not to split hairs too finely, but I think of it as defining what it means
to use a particular datatype as a function.

> 	:- func ''(string, int) = char.
> 	String(Int) = string__index_det(String, Int).
> 
> This would allow you to define things like
> 
> 	:- func ''(Seq, int) = Elem <= seq(Seq, Elem).
> 	Seq(X) = lookup(Seq, X).

In some ways, this is a nicer approach.  But it worries me syntactically.
Firstly, it does not suggest to me that

	String 3
and
	String (3)
and
	String(3)

should be different things.  Do you really want to allow the first
or second form?  And I suspect you won't be able to parse the first two
forms, anyway, because you need the types to decide if it's an application.

Also, I don't see how it would handle treating a value as a binary (or
higher arity) function.  Would I write:

	:- func ''(matrix, int, int) = int.
	Matrix(Row,Column) = matrix__lookup(Matrix,Row,Column).

Anyway, however it is declared, allowing terms to be syntactically used as
functions would be a nice facility.

-- 
Peter Schachte <schachte at cs.mu.OZ.AU>  Remember, "Euphemisms are for the
http://www.cs.mu.oz.au/~schachte/      differently brained."
Phone:  +61 3 8344 9166                -- jamie at cdevil.unx.sas.com (James
Fax:    +61 3 9348 1184                Cooper) 
--------------------------------------------------------------------------
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