[m-dev.] syntax proposals

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 2 17:16:19 AEDT 2001


Here's a couple of suggestions from Ralph for Mercury syntax extensions.

(1) Allow use of equivalence types in `:- func' and `:- pred'
    declarations.

For example, if you have

	:- type filter(T) == (func(list(T)) = list(T)).

then the proposal is to allow you to write

	:- func foo : filter(T).

or perhaps

	:- func foo `with_type` filter(T).

This would mean the same as

	:- func foo(list(T)) = list(T).

(2) Nested function and predicate definitions

Currently you can use lambda expressions to define local function
nested within the definitions of other functions,
but that doesn't work if the functions are recursive.

The proposal is that function and predicate bodies can contain
nested declarations inside `where [ ... ]'.

E.g.

	fold(Op, L) = fold_2(L, 0)
		where [
			func fold_2(list(int), int) = int,
			% /* pragmas would also be allowed, e.g. */
			% pragma promise_pure(fold_2/2),
			% pragma inline(fold_2/2),
			% pragma memo(fold_2/2),
			fold_2([], S) = S,
			fold_2([X|Xs], S0) = fold_2(Xs, S0 `Op` X),
		].

Here the variable `Op' scopes over the definition of fold_2.

In general it might make sense to allow any kind of declaration at
all inside the `where [ ... ]', including type declarations,
type classes, etc.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  | "... it seems to me that 15 years of
The University of Melbourne         | email is plenty for one lifetime."
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- Prof. Donald E. Knuth
--------------------------------------------------------------------------
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