[m-dev.] Proposal: sequence quantification
Ralph Becket
rbeck at microsoft.com
Thu Jan 4 22:21:31 AEDT 2001
>From schachte at cs.mu.OZ.AU on 03/01/2001 13:09:59
>
> That's up in the air a bit now. I have a Prolog implementation of most
> of this, but in many ways it's easier in Prolog than Mercury. On the
> other hand, I've put some work into optimization for Prolog that's
> completely unnecessary for Mercury. Let's just say that we're shooting
> for generating the sort of first-order code you would write if you were
> thinking about efficiency.
Have you got some draft or sketch design notes you wouldn't mind me
looking at?
> > Presumably this could also be written as
> >
> > for E in Sequence as Curr initially E finally LastElt ::
> > next Curr = E
>
> No, E is scoped to the quantified goal, and can't be used in other
> quantifiers in the same quantification.
Yes, I spotted that just after I sent it.
> > `as' requires both L and R sequences to be the same length - does it
> > fail quietly if they are not (i.e. is semidet code generated) or is
> > an exception thrown?
>
> It quietly fails.
>
> > If the former, I think there is scope for a
> > version with the latter behaviour as that will be quite common
> > (call it `det_for' or something, or maybe make `for' the det case).
>
> Hmmmmm. Yes, I can see that being useful. OTOH, one big point of this
> whole thing is to be useful in different modes, including generating
> sequences. That means that:
>
> det_for A in L1 as B in L2 :: Goal, L2 = [a, b, c]
>
> might quietly fail while
>
> L2 = [a, b, c], det_for A in L1 as B in L2 :: Goal
>
> would raise an exception. That doesn't seem very nice to me. What's
> the language's position on commutativity of conjunction with respect to
> the finite failure set?
My thinking is that since 90%+ of the code we write is functional and
single-mode that the transformation and syntax should make that case
as straightforward as possible - so I'd rather see a `semidet_for' that
quietly failed and reserve `for' for the common exception throwing case.
Mode analysis should then allow the compiler to happily reorder your code
above to do the right thing.
> > Can these be composed, as in
> >
> > for E in List once E >=0 while E < 10 ...
>
> Yup.
Excellent - this is really quite powerful.
> > On the matter of the transformation only applying to lists in the
> > first instance, I presume that `X initially A finally Z' will be
> > an accumulator
>
> That's the plan, though as I said, it's still a bit up in the air. The
> Prolog version generates an accumulator pair, though it works on an
> older, uglier syntax instead of `initially ... finally ...'.
Semantics first, syntax later :)
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
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