[m-dev.] 0.13 release: op/3 syntax
Peter Schachte
schachte at csse.unimelb.edu.au
Sat Mar 4 18:36:13 AEDT 2006
On Sat, Mar 04, 2006 at 05:15:30PM +1100, Peter Moulder wrote:
Another Peter heard from!
> I believe the particular example Peter gave (where the argument of '***'
> was an arbitrary goal) wouldn't work in Mercury.
Not until the mode system is improved to allow output arguments in
closures.
> > I'd like to be able to use 'in' as an infix operator for list and set
> > membership.
> You can already use `member`.
X `member` L doesn't look any better to me than member(X,L). Taste, I
guess. Too bad we're stuck with ascii.
> > forall Template in Sequence :: Goal
>
> I'm not sure what the above does. Mercury already allows
>
> ( all[X] X `member` Sequence => Goal(X) )
My version means exactly the same as the Mercury one, except that it
can produce bindings. Actually, I got it a little wrong; I forgot I
had changed things. Here are a few examples:
forall X in list(L) do X = 3
unifies every element of L with 3.
forall X in list(L) as I in 1..N do X is I*I
unifies L with a list of the first N squares.
forall I in 1..N as (0->S0->S->Sum) do S is S0 + I*I
unifies Sum with the sum of the first N squares. I'm not entirely
happy with the syntax of this one. It's meant to suggest that the
first S0 is 0, at each iteration we compute S from S0, each
iteration's S0 is the previous iteration's S, and Sum is the final S.
Basically, this does everything all the map/filter/fold predicates
(and all the weird combinations and arities) do, and is extensible to
allow iteration over sets, maps, etc.
This is all documented in
@InProceedings{sch-padl-03,
author = {Peter Schachte},
title = {Sequence Quantification},
pages = {128--144},
year = 2003,
booktitle = {Practical Aspects of Declarative Languages},
editor = {Veronica Dahl and Philip Wadler},
publisher = springer,
series = lncs,
Volume = 2562
}
It could all be done without operators, of course, but it wouldn't be
as easy to read. Eg, the last example would have been something like
forall((I,S0,S), (range(1,N),thread(0,Sum)), (S is S0 + I*I)))
--
Peter Schachte Do not meddle in the affairs of wizards, for
schachte at cs.mu.OZ.AU they are subtle and quick to anger.
www.cs.mu.oz.au/~schachte/ -- J. R. R. Tolkien
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
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