[mercury-users] higher order syntax

Ralph Becket rbeck at microsoft.com
Fri Feb 11 21:55:43 AEDT 2000


> On 10-Feb-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> 
> I don't understand why you would ever
> write `:- func f = (func(T1) = T2).'.
> Why not just write `:- func f(T1) = T2.'?

Well, when programming in the monadic style you end up
writing functions that are basically just compositions
of other functions.  For example, if I have

:- type parse(I, A, X)
	--->	no
	;	yes(A, list(I))
	;	error(X, list(I)).

:- type parser(I, A, X) == (func(list(I)) = parser(I, A, X)).

And then define some primitive parsers and parser combinators, 
I might want to compose them thus:

:- func letter_number = parser(char, pair(char-int), _).

letter_number =
	letter `>>=` (func(L) =
	number `>>=` (func(N) =
	return(L-N))).

Now I could write this as

:- func letter_number(list(char)) = parse(char, pair(char-int), _).

letter_number(Cs) =
	apply(
		(letter `>>=` (func(L) =
		 number `>>=` (func(N) =
		 return(L-N)))),
		Cs
	).

but that would be horrid.
> 
> > Similarly, if F has type `func(T1) = (func(T2) = T3)'
> > then I have to write `apply(F(X), Y)'.
> 
> That example makes more sense.
> 
> > Would it be
> > hard to extend the convenience syntax so that one
> > could write `F(X)(Y)' instead?  Or, if it makes life
> > any easier for the parser writers, `(F(X))(Y)' and
> > `(f)(X)'?  This syntax looks clearer and less mixed up
> > and, IIRC, it's what the XSB/HiLog people do.
> 
> Probably not.
> [...]
> 
> Currently the only binary prefix operators in Mercury syntax
> are `some', `all', and the obsolete `lambda'.  So that issue is
> not a big deal, I guess.  There is a backwards compatibility issue
> with code like `some[X](...)', though, which would need to
> be changed to e.g. `some [X] (...)'.

I suspect that some/all appear very rarely in existing code; even
the existential types stuff hasn't made huge inroads yet, as far
as I can see.

Want to bite the bullet?

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