[m-dev.] syntax proposals
Ralph Becket
rafe at cs.mu.OZ.AU
Wed Nov 7 10:51:33 AEDT 2001
Fergus Henderson, Wednesday, 7 November 2001:
> On 06-Nov-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> >
> > Will the precedence of 'func' allow this without parentheses?
>
> No, good point, the `func' declaration would need to be parenthesized.
Which is unfortunate.
One thing that I find aesthetically distressing is that we currently
have different syntax for declarations at the top-level and for nested
declarations such as with typeclass and instances.
This stems from using lists to group nested declarations and
definitions. Can we introduce a different kind of `list' for this
purpose which perserves the top-level syntax. That is, rather than
write
:- typeclass c(T) where [
func f(T) = int,
pred p(T),
mode p(in) is semidet,
...
].
we would say
:- typeclass c(T) where [|
:- func f(T) = int.
:- pred p(T).
:- mode p(in) is semidet.
...
|].
where [| and |] group a set of declarations written in the standard
top-level syntax.
> > 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.
I think I'd vote in favour of that change.
> > 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).
We could extend the above notation to cover this case if we wanted,
for example
[|
f([]) = base.
f([X | Xs]) = g(X, f(Xs)).
|]
where
[|
...definition of local func g...
|].
- Ralph
--------------------------------------------------------------------------
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