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

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Oct 21 01:46:42 AEDT 2000


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

	:- 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).

which would not be possible with the syntax that you proposed.
This approach would also naturally support overloading on arity or module.

The changes required to the compiler to allow user-defined overloading
of the higher-order function call syntax in this way are very small and do
not complicate the compiler.  (Unfortunately, doing the same for user-defined
overloading of the higher-order predicate call syntax is considerably
more difficult.)

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