Functional programming in Python
S. Alexander Jacobson
alex@shop.com
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.
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.
-Alex-
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
> be
>
> (foo . bar . baz) x
>
> or
>
> 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
>
> Regards,
> Tom
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___________________________________________________________________
S. Alexander Jacobson Shop.Com
1-646-638-2300 voice The Easiest Way To Shop (sm)