Yes, exactly.
> So, as it is just a matter of how the lhs was written, perhaps it is
> not necessary to emphasise the underlying equivalence of n-arg lambdas
> to 1-arg lambda? My guess is that lambda calculus afficinados will
> know about it and others will prefer the syntactical consistency of
> nargs giving n for n-arg lambda if that is how it was written.
Right, I'm working on that right now. Once that is done, I'll also
reconsider the left-linearity restriction.
Albert, I thought left-linearity was written in stone to keep the interpreter fast and lean. Is the change in heart due to
pure *always* producing machine code through LLVM? Does this mean we will be able to write equations like
x*y+x*z = x*(y+z);
as we did in Q?
e.r.
Well, quoting myself from a previous thread [1]: "It's a design
decision, and as such open to debate." Debate it we did :), and the
general consensus seemed to be that non-linearities would be nice to
have. I also mentioned that this wouldn't be difficult to implement; it
doesn't really make the interpreter much fatter, I'm more concerned with
the "hidden magic" issue here, see below.
[1]
http://groups.google.com/group/pure-lang/browse_thread/thread/d8bd796a11fb49b0
One of my objections was that non-linearities would cause confusion
because of the way that lambdas were handled. That is fixed now (as of
r2821) so that we have proper multi-argument lambdas which are given the
same treatment as named functions when it comes to non-linearities. I
must say that I'm quite happy with that; it seems to be the Right Thing
after all.
My other objection was the hidden inefficiencies (and even potential
nontermination issues, with lazy data) in non-linearities. (Note that
this isn't about the efficiency of the interpreter or generated code,
it's about the ease with which the programmer himself can write horribly
inefficient Pure programs.) That argument (as well as the
'non-linearities as typos' issue) still holds, but I have to weigh it
against the added convenience of non-linear definitions and Pure's
general "laissez fair" attitude when it comes to enabling the programmer
to blow his leg off. ;-)
I also mentioned a few theoretical difficulties (mostly related to
modularity of term rewriting w.r.t. confluence and termination
properties), but these aren't really that important in Pure because of
the deterministic reduction strategy.
Note that the main objection against non-linearities in *Haskell* (and
other H/M-typed languages), namely that Haskell doesn't have a notion of
syntactic equality of terms (instead, a non-linear variable would have
to be an instance of the Eq class, over which the compiler has no
semantic control), isn't an issue with Pure, as syntactic equality is
always defined and has a clear semantics.
So I'm willing to give it a go now; I can always add a paragraph about
the pitfalls of non-linearity to the "Caveats and Notes" section later.
> Does this mean we will be able to write equations like
>
> x*y+x*z = x*(y+z);
>
> as we did in Q?
Yup, that's what it's all about. And yes, it *is* convenient, especially
when doing computer algebra.
Cheers,
Albert
> My other objection was the hidden inefficiencies (and even potential
> nontermination issues, with lazy data) in non-linearities. (Note that
> this isn't about the efficiency of the interpreter or generated code,
> it's about the ease with which the programmer himself can write horribly
> inefficient Pure programs.) That argument (as well as the
> 'non-linearities as typos' issue) still holds, but I have to weigh it
> against the added convenience of non-linear definitions and Pure's
> general "laissez fair" attitude when it comes to enabling the programmer
> to blow his leg off. ;-)
I think, especially given the typo concern, that it would be appropriate
to print a warning when encountering a nonlinear rule. (There needs to
be a command to silence such warnings, of course.)
> I also mentioned a few theoretical difficulties (mostly related to
> modularity of term rewriting w.r.t. confluence and termination
> properties), but these aren't really that important in Pure because of
> the deterministic reduction strategy.
True. Still, it's easier to reason about complex Pure functions if
you can easily write disjoint rules and don't have to depend on the
source-code order.
--
John Cowan co...@ccil.org http://ccil.org/~cowan
Objective consideration of contemporary phenomena compel the conclusion
that optimum or inadequate performance in the trend of competitive
activities exhibits no tendency to be commensurate with innate capacity,
but that a considerable element of the unpredictable must invariably be
taken into account. --Ecclesiastes 9:11, Orwell/Brown version
That's nice to hear.
e.r.
Yea, I think John has the right idea.
e.r.
Libor
Well, it doesn't make much sense to me to add a language feature and
then warn about its uses by default; that's just annoying. I could maybe
add a pragma (off by default) which could selectively be turned on in
the source, though.
> True. Still, it's easier to reason about complex Pure functions if
> you can easily write disjoint rules and don't have to depend on the
> source-code order.
Right, but IMHO that's a question of programmer discipline. If you want
real equational logic semantics then you'll just have to stick to
confluent and terminating rewriting systems. The Pure compiler doesn't
keep you from writing your definitions that way, but it won't force you
to do it either.
> Well, it doesn't make much sense to me to add a language feature and
> then warn about its uses by default; that's just annoying.
That sounds like a matter of timing. Suppose the feature had been there
all the time (as in Q) and you had had complaints: "Hey, my foot is half
shot off here". Adding a warning would make sense then, hmmm? So I'm
just suggesting that you preempt that.
When current behavior makes something an error, people unconsciously rely
on the error being reported to protect them against making it. Extending
the system to make the behavior do something unusual takes away that
security blanket. (This is why you can't subset a programming language
by just teaching people part of it; inevitably they write something that
happens to be a feature of the full language, and then they can't debug
their programs. Such people need computer assistance in the form of a
precompiler or linter.)
> Right, but IMHO that's a question of programmer discipline.
If you want C, you know where to find it. :-)
> If you want real equational logic semantics then you'll just have
> to stick to confluent and terminating rewriting systems. The Pure
> compiler doesn't keep you from writing your definitions that way,
> but it won't force you to do it either.
"The task is not yours to complete, but neither are you free to desist
from it." --Rabbi Tarfon, 1st century C.E.
--
My corporate data's a mess! John Cowan
It's all semi-structured, no less. http://www.ccil.org/~cowan
But I'll be carefree co...@ccil.org
Using XSLT
On an XML DBMS.
I can see your point, but I prefer to wait until the complaints roll in.
I really don't like the idea to warn about legal code if there's no way
to actually detect the dubious cases. (However, the compiler does an
occurrence check to throw out "as" variables repeated in the
corresponding subpatterns (such as xs@(x:xs)), since these can't
possibly yield finite matches anyway.)
Support for non-linearities is implemented as of r2834. So if you're
running the latest svn, rules like the following will do the right thing
now:
a*c+b*c = (a+b)*c;
a*b+a*c = a*(b+c);
The same applies to repeated variables in the lhs of lambdas, case, when
and let/const, of course. I didn't test these heavily yet, so please
consider this experimental and report any bugs that you find. I hope
that I can release this as Pure 0.40 before xmas.