Should `(flip (^^))` work?

Hi, I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)? 2 `(flip (^^))` (3%4) Thanks, Maurício

On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:
Hi,
I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)?
2 `(flip (^^))` (3%4)
No it shouldn't work. The fact that the opening and closing marks are the same suggests that it shouldn't. You can fake it though. x -| f = f x f |- x = f x 2 -| flip (^^) |- (3%4)

Derek Elkins wrote:
On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:
Hi,
I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)?
2 `(flip (^^))` (3%4)
No it shouldn't work. The fact that the opening and closing marks are the same suggests that it shouldn't. You can fake it though.
x -| f = f x f |- x = f x
2 -| flip (^^) |- (3%4)
Isn't naming the expression 'flip (^^)' much clearer?

Rafael C. de Almeida a écrit :
Derek Elkins wrote:
On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:
Hi,
I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)?
2 `(flip (^^))` (3%4) No it shouldn't work. The fact that the opening and closing marks are the same suggests that it shouldn't. You can fake it though.
x -| f = f x f |- x = f x
2 -| flip (^^) |- (3%4)
Isn't naming the expression 'flip (^^)' much clearer?
I think that is an interesting question about programming style. In practical code I think we should have a balance between the complexity of big expressions and the complexity of too many names. Best, Maurício

On Mon, Sep 15, 2008 at 8:09 PM, Mauricio
Rafael C. de Almeida a écrit :
Derek Elkins wrote:
On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:
Hi,
I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)?
2 `(flip (^^))` (3%4)
No it shouldn't work. The fact that the opening and closing marks are the same suggests that it shouldn't. You can fake it though.
x -| f = f x f |- x = f x
2 -| flip (^^) |- (3%4)
Isn't naming the expression 'flip (^^)' much clearer?
I think that is an interesting question about programming style. In practical code I think we should have a balance between the complexity of big expressions and the complexity of too many names.
Hm, I was suggesting a local name in a where or let clause. In my experience, if there are too many local names it's evidence that you should break up the function into other functions. But what I'm saying is that I'd rather read something like: 2 `flippedPow` (3%4) then just check what flippedPow is on the where clause than reading 2 -| flip (^^) |- (3%4) and having to figure out what -| and |- do.

Mauricio wrote:
Hi,
I tested the expression below and it doesn't work. Is there some way to achieve that (i.e., turning an expression inside parenthesis into an operator)?
2 `(flip (^^))` (3%4)
Another solution if you don't like defining extra (-|) and (|-) operators is:
($2) (flip (^^)) (3%4)
The right section of function application is type lifting. The general form of this construction is:
($x) (f a b c...) y z...
Which is equal to (f a b c... x y z...). That is, the construction lets you raise any argument out to before the function, thus making the partially applied function into an infix between |x| and |y x...|. -- Live well, ~wren
participants (5)
-
Derek Elkins
-
Mauricio
-
Rafael Almeida
-
Rafael C. de Almeida
-
wren ng thornton