Functional programming in Python
S. Alexander Jacobson
Fri, 25 May 2001 13:54:35 -0400 (Eastern Daylight Time)
Does anyone know why the haskell designers did not make the syntax
right associative? It would clean up a lot of stuff.
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
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.
On Fri, 25 May 2001, Tom Pledger wrote:
> Peter Douglass writes:
> | but in ( foo ( bar (baz x) ) )
> | You would want the following I think.
> | foo . bar . baz x
> | which does have the parens omitted, but requires the composition
> | operator.
> Almost. To preserve the meaning, the composition syntax would need to
> (foo . bar . baz) x
> foo . bar . baz $ x
> or something along those lines. I favour the one with parens around
> the dotty part, and tend to use $ only when a closing paren is
> threatening to disappear over the horizon.
> do ...
> return $ case ... of
> ... -- many lines
> Haskell-Cafe mailing list
S. Alexander Jacobson Shop.Com
1-646-638-2300 voice The Easiest Way To Shop (sm)