[m-dev.] syntax proposals

Peter Schachte schachte at cs.mu.OZ.AU
Tue Nov 6 22:34:48 AEDT 2001


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

Will the precedence of 'func' allow this without parentheses?  In any case,
the precedence of :- certainly won't.  The idea of nested
functions/predicates is fine, but this syntax doesn't seem quite right.
Also, I think definitions should be nested within a *predicate or function*,
not a single *clause*, because it's not unlikely multiple clauses for the
function or predicate will want to refer to the nested definition, and it
would be a shame to be forced to use an explicit disjunction just so you
could use this nested defintion syntax.

Maybe you could think of a way to press nested modules into service here?
Some simplified syntax for declaring a nested module with a single export?
That might not be quite right either, because you really want the pred/func
with nested definitions to live in the outer module.  But nested modules
come so close to doing what you want that it doesn't seem like a good idea
to add a whole new feature just like them.

-- 
Peter Schachte              A classic is something that everybody wants to
schachte at cs.mu.OZ.AU        have read and nobody wants to read.
www.cs.mu.oz.au/~schachte/      -- Mark Twain 
Phone: +61 3 8344 9166      
--------------------------------------------------------------------------
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