[Haskell-cafe] Why are && and || right-associative?

Jerzy Karczmarczuk jerzy.karczmarczuk at unicaen.fr
Fri Apr 19 19:43:46 UTC 2019


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/*

Everybody will be happy. Bon courage.

Jerzy Karczmarczuk

*/
/*

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190419/08559757/attachment.html>


More information about the Haskell-Cafe mailing list