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

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Oct 21 18:26:33 AEDT 2000


On 21-Oct-2000, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Sat, Oct 21, 2000 at 01:46:42AM +1100, Fergus Henderson wrote:
> > 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.

Well, it's defining what function application syntax means for some
particular sequence of datatypes (the function-like object, and its
operands).  But it need not be associated with a particular data type.
Since (unlike equality) this is a purely syntactic notion, not a
semantic notion, it's fine for the syntax to be defined to mean
different things in different modules, even for the same argument
types.

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

The Mercury language reference manual already says that the first two
are syntax errors, and the third one means ''(String, 3).
I don't propose to change this.

What I was talking about was just allowing ''(String, 3) to be
*either* a higher-order call or a call to a call to a user-defined
''/N function (with the usual overloading mechanism used to
distinguish between these two cases).  Currently ''(String, 3) is
always treated as a higher-order call, never a call to a user-defined
''/N function.

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

Yes.

-- 
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"
                                    |     -- 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