[m-dev.] syntax proposals

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 7 10:21:42 AEDT 2001


On 06-Nov-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > (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?

No, good point, the `func' declaration would need to be parenthesized.

> In any case, the precedence of :- certainly won't.

The proposal was that `:-' wouldn't be required in nested declarations,
to be consistent with typeclass declarations.

Personally I favour dropping the requirement for `:-' in top-level
declarations too, although this proposal didn't get much support last
time I raised it.

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

Well, it seems to work OK in Haskell, even though Haskell has the same
limitation (nested definitions are only visible within a clause, not
the whole function).

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