Functional programming in Python
Zhanyong Wan
zhanyong.wan@yale.edu
Fri, 25 May 2001 14:00:54 -0400
"S. Alexander Jacobson" wrote:
>
> Does anyone know why the haskell designers did not make the syntax
> right associative? It would clean up a lot of stuff.
>
> Haskell Non-Haskell
> Left Associative Right Associative
> foo (bar (baz (x))) foo bar baz x
> foo $ bar $ baz x foo bar baz x
> add (square x) (square y) add square x square y
> add (square x) y add square x y
> ------------From Prelude----------------------
> map f x (map f) x
> f x (n - 1) x f x n - 1 x
> f x (foldr1 f xs) f x foldr1 f xs
> showChar '[' . shows x . showl xs showChar '[] shows x showl xs
>
> You just need to read from right to left accumulating a stack of
> arguments. When you hit a function that can consume some arguments, it
> does so. There is an error if you end up with more than one value on
> the argument stack.
Note that in your proposal,
add square x y
is parsed as
add (square x) y
instead of
add (square (x y)),
so it's not right associative either.
As you explained, the parse of an expression depends the types of the
sub-expressions, which imo is BAD. Just consider type inference...
-- Zhanyong