[Haskell-cafe] Why are && and || right-associative?
Albert Y. C. Lai
trebla at vex.net
Mon Apr 22 04:44:03 UTC 2019
On 2019-04-19 3:43 p.m., Jerzy Karczmarczuk wrote:
> Le 19/04/2019 à 19:31, Albert Y. C. Lai a écrit :
>> I am late to this discussion but here is my solution.
>> This is really just story-telling to end-users.
>> The real story you want to tell everyone is this: "x && y && z && t"
>> means Scheme's "(and x y z t)", and it means you try the sequence
>> from left to right, stopping at the first incident of "false".
>> As many of you have observed, it doesn't matter, a compiler writer
>> already knows it's "(and x y z t)" and generates the correct code and
>> not bother to split hair.
> Very, ehm, interesting methodology...
> I suspect that you missed that part of the discussion where people
> discussed parsing. I don't know if you ever taught compilation, but
> imagine that your students ask you:
> */HOW /**/"x && y && z && t" is transformed into /**/"(and x y z t)" ?/*
> Will your answer be:
> */it doesn't matter, a compiler writer already knows it's "(and x y z
> t)" and generates the correct code and not bother to split hair/*
What would you tell students about commas and semicolons in the
following? Are these commas and semicolons left associating? Right
associating? Both? Neither? Has anyone even asked? How to parse
them? I would tell the same.
Pascal's "begin foo() ; tora() ; tigger() end"
C's "x = (y=10 , y=f(y) , y=g(y) , y);"
Haskell's "f x | g x > 0 , h x < 0 , sin x > 0 = ()"
Prolog's "g(X,Y) :- parent(X,C1) , parent(C1,C2) , parent(C2,Y)."
Matlab's "[3+4i , 3 , 5-i ; 1-i , 1+i , 1 ; 7+8i , 4-3i , -i]"
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe