Syntax proposal for "reverse apply"/"pipeline apply" (flip ($))

Hello, i am completely new to Haskell, but i am somewhat fascinated by lambda-calculus and programming. For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell. I think that a good syntax would be "|^", for example: square x = x * x y = 3 |^ square -- y == 9 Explanation: * i would have suggested just ^, but it would conflict with number exponentiation, * it is rather common in mathematics to write function application in exponential notation: x ^ f instead of f(x), especially if f is an automorphism of some structure, * (flip ($)) is exactly the exponentiation of Church numerals, * in "The calculi of lambda-conversion", Alonzo Church uses the "shorthand" notation "[N^M]" for "(MN)", where M and N are lambda-terms. * I am probably not the only person missing the ability to apply functions from the right: http://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-fo... Well, other notations i've thought of are "\^" and "~$". Alexey.

On 17/04/2014, at 10:25 AM, Alexey Muranov wrote:
For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell.
Oh, you mean like F#'s "|>" operator?
(|>);; val it : ('a -> ('a -> 'b) -> 'b) = fun:it@2 (<|);; val it : (('a -> 'b) -> 'a -> 'b) = fun:it@3-1
I think that a good syntax would be "|^", for example:
If we were to copy an operator from F#, it would have been nice to copy the F# name for it. Sadly, Data.Sequence already uses |> . Hoogle doesn't find a (|^), so that might work. I will say, however, that whenever I've read chunks of F# with long chains of |> operators, I've wanted to rewrite them using point-free style.

On Thursday, April 17, 2014 1:38:48 AM UTC+2, Richard A. O'Keefe wrote:
On 17/04/2014, at 10:25 AM, Alexey Muranov wrote:
For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell.
Oh, you mean like F#'s "|>" operator?
If we were to copy an operator from F#, it would have been nice to copy the F# name for it. Sadly, Data.Sequence already uses |> . Hoogle doesn't find a (|^), so that might work.
No, in fact i wanted to copy it from the exponential notation for function application. In particular, it would need to be right-associative: y |^ x |^ f == y |^ (x |^ f) == f x y Maybe a left-associative version can be defined too, by something like this: x ^| g ^| f == (x ^| (g |^ f) = f (g x)

Interesting. I've never seen it proposed as right-associative before. Just
FYI, the implementation is as simple as this:
infixr 1 |^
(|^) :: a -> (a -> b) -> b
x |^ f = f x
Then you can write:
3 |^ 2 |^ (^) -- produces 2^3 = 8
It seems very odd to me. I don't know why you'd want to apply the arguments
backwards one by one. However, lens and diagrams both provide examples
where you want to start with a value and apply functions "forwards" one by
one, which is why their corresponding operators are left-associative.
-- Dan Burton
On Wed, Apr 16, 2014 at 4:49 PM, Alexey Muranov
On Thursday, April 17, 2014 1:38:48 AM UTC+2, Richard A. O'Keefe wrote:
On 17/04/2014, at 10:25 AM, Alexey Muranov wrote:
For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell.
Oh, you mean like F#'s "|>" operator?
If we were to copy an operator from F#, it would have been nice to copy the F# name for it. Sadly, Data.Sequence already uses |> . Hoogle doesn't find a (|^), so that might work.
No, in fact i wanted to copy it from the exponential notation for function application. In particular, it would need to be right-associative:
y |^ x |^ f == y |^ (x |^ f) == f x y
Maybe a left-associative version can be defined too, by something like this:
x ^| g ^| f == (x ^| (g |^ f) = f (g x)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On 17 avr. 2014, at 03:41, Dan Burton
Interesting. I've never seen it proposed as right-associative before.
Yes, maybe it was a bad idea after all. I just thought that the caret/exponentiation symbol may fit well the semantics, but unfortunately with the right associativity it would not allow to get rid of parentheses in common use, and with left associatifity it would not look like exponentiation. Alexey.

lens defines & for this purpose (not that one would want to pull in the
behemoth that is lens as a dependency just for that).
On Wed, Apr 16, 2014 at 3:25 PM, Alexey Muranov
Hello,
i am completely new to Haskell, but i am somewhat fascinated by lambda-calculus and programming.
For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell.
I think that a good syntax would be "|^", for example:
square x = x * x y = 3 |^ square -- y == 9
Explanation:
* i would have suggested just ^, but it would conflict with number exponentiation,
* it is rather common in mathematics to write function application in exponential notation: x ^ f instead of f(x), especially if f is an automorphism of some structure,
* (flip ($)) is exactly the exponentiation of Church numerals,
* in "The calculi of lambda-conversion", Alonzo Church uses the "shorthand" notation "[N^M]" for "(MN)", where M and N are lambda-terms.
* I am probably not the only person missing the ability to apply functions from the right:
http://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-fo...
Well, other notations i've thought of are "\^" and "~$".
Alexey. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

In the "lens" package, this is (&) at infixl 1. In the "diagrams" package,
this is (#) at infixl 8. You're certainly not the first to want this, but
nobody can ever agree what it should be called or what fixity it should
have. You can always just define it yourself.
-- Dan Burton
On Wed, Apr 16, 2014 at 3:25 PM, Alexey Muranov
Hello,
i am completely new to Haskell, but i am somewhat fascinated by lambda-calculus and programming.
For whatever it is worth, i would like to propose for discussion a syntax for "(flip ($))" operation in Haskell.
I think that a good syntax would be "|^", for example:
square x = x * x y = 3 |^ square -- y == 9
Explanation:
* i would have suggested just ^, but it would conflict with number exponentiation,
* it is rather common in mathematics to write function application in exponential notation: x ^ f instead of f(x), especially if f is an automorphism of some structure,
* (flip ($)) is exactly the exponentiation of Church numerals,
* in "The calculi of lambda-conversion", Alonzo Church uses the "shorthand" notation "[N^M]" for "(MN)", where M and N are lambda-terms.
* I am probably not the only person missing the ability to apply functions from the right:
http://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-fo...
Well, other notations i've thought of are "\^" and "~$".
Alexey. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thursday, April 17, 2014 1:49:31 AM UTC+2, Dan Burton wrote:
In the "lens" package, this is (&) at infixl 1. In the "diagrams" package, this is (#) at infixl 8. You're certainly not the first to want this, but nobody can ever agree what it should be called or what fixity it should have. You can always just define it yourself.
(#) does not look too bad either.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 In my opinion we should just have '|>' and '<|' from F#. They are much nicer, being mnemonics for direction. And '|>' is just orders of magnitude nicer than 'flip ($)'. But alas, I fear we are stuck with this wart. - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNPyqQACgkQRtClrXBQc7XDHQEAp0SL5NZJMf3MEvLcst/dr+O2 nPasMEggHMaoF6BsEBIA/RWaPBf//EVXWKUR9qpsVDBbSAPZa5T7jcoXCIZ8Wf9I =qE8a -----END PGP SIGNATURE-----

On 17 avr. 2014, at 14:35, Alexander Berntsen
In my opinion we should just have '|>' and '<|' from F#. They are much nicer, being mnemonics for direction. And '|>' is just orders of magnitude nicer than 'flip ($)'. But alas, I fear we are stuck with this wart.
Then i think symmetric aliases for '(.)' and 'flip (.)' would also be needed. Still this would not make the language completely symmetric because it is impossible: * 'f x' would still be 'f x', * a left-associative and a right-associative operator symbols cannot have the same precedence, so '|>' and '<|' would need to have different precedence. Maybe just some naming convention is needed for the names of the flips of commongly flipped operators? I am thinking about something silly like '~$', '~.', or '-$', '-.', or maybe some other unary operator symbol can be used sefely as a prefix here... Alexey.

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/04/14 14:58, Alexey Muranov wrote:
Then i think symmetric aliases for '(.)' and 'flip (.)' would also be needed. F# solved this elegantly with '>>' and '<<', but these are already used in Haskell. But I see these as separate issues, and I use 'flip ($)' a lot more often than 'flip (.)'.
* a left-associative and a right-associative operator symbols cannot have the same precedence, so '|>' and '<|' would need to have different precedence. Why? In the languages I have used '|>' and '<|', they have the same precedence.
Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNP0bQACgkQRtClrXBQc7XzEQD/XR5vIrDLR/zWeqKA68D8mbzM 6wgeGeFipqC7QSeWdiYBAJBhgVHqfo8JghewXweF5f93QnrcdLF/khIFuJGUA+Rq =JtCP -----END PGP SIGNATURE-----

On Thu, Apr 17, 2014 at 3:05 PM, Alexander Berntsen
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256
On 17/04/14 14:58, Alexey Muranov wrote:
Then i think symmetric aliases for '(.)' and 'flip (.)' would also be needed. F# solved this elegantly with '>>' and '<<', but these are already used in Haskell. But I see these as separate issues, and I use 'flip ($)' a lot more often than 'flip (.)'.
Haskell has (>>>) and (<<<) in Control.Arrow if you want symmetric operators for this. Erik

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/04/14 15:08, Erik Hesselink wrote:
Haskell has (>>>) and (<<<) in Control.Arrow if you want symmetric operators for this. Forgot all about those. Shows how little I need the backward composition operator. Thanks for reminding me.
Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNP1QIACgkQRtClrXBQc7UGagD/eupkBoVgYhi0tXVzU+0sTJRJ kKzL2HjuzaVfnILtLoAA/3loykUQOqJZ+MAN+pKwn+X2NRBXjFs9mYbk3YbQ++Ny =ka4w -----END PGP SIGNATURE-----

http://hackage.haskell.org/package/lens-4.1.2/docs/Control-Lens-Lens.html#v:... On 17/04/14 23:20, Alexander Berntsen wrote:
On 17/04/14 15:08, Erik Hesselink wrote:
Haskell has (>>>) and (<<<) in Control.Arrow if you want symmetric operators for this. Forgot all about those. Shows how little I need the backward composition operator. Thanks for reminding me.
Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Tony Morris http://tmorris.net/

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/04/14 15:28, Tony Morris wrote:
http://hackage.haskell.org/package/lens-4.1.2/docs/Control-Lens-Lens.html#v:... I
know about this. It has already been mentioned by Taylor Hedberg. And as correctly observed by Taylor, one does not simply walk into Mord^W^W^Wpull in lens just to get a simple function that you can define yourself without much trouble. I assumed this thread was about how people felt about having a backward application operator in prelude. And I would like to repeat my argument that '<|' and '|>' are much nicer mnemonically than '$' and '&'. (Though Edward has made the case for '&' being read "and", I don't think that's very nice. He certainly can't make the opposite case for '$'.) - -- Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNP2G8ACgkQRtClrXBQc7X0GwD/at62rzxwrjDR4Aa4hZgEfSza LExn7hhRoSWObmVBV8wA/iKa9y9tik8Bt9FPGnbgkwu3DBx1YBhtn/2WAeh7OFkZ =B6Ih -----END PGP SIGNATURE-----

On 17 avr. 2014, at 15:05, Alexander Berntsen
* a left-associative and a right-associative operator symbols cannot have the same precedence, so '|>' and '<|' would need to have different precedence. Why? In the languages I have used '|>' and '<|', they have the same precedence.
I do not know F#, and maybe i am missing something, but assuming that x |> f |> g == (x |> f) |> g and g <| f <| x == g <| (f <| x) what are x |> f <| y and g <| x |> f ?

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 On 17/04/14 15:11, Alexey Muranov wrote:
what are
x |> f <| y
and
g <| x |> f "conflicting associativity" errors.
Alexander alexander@plaimi.net https://secure.plaimi.net/~alexander -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iF4EAREIAAYFAlNP1BEACgkQRtClrXBQc7WKpgEAp7QSKyl7ZFkkAznJVZgRzH6y OSGskwCithbusAzW9ScBAIVmebyf0lk77Oy7GAG4cl7oc0NLRsj77cAjaUqBLPor =FCx0 -----END PGP SIGNATURE-----

On 17 avr. 2014, at 15:16, Alexander Berntsen
On 17/04/14 15:11, Alexey Muranov wrote:
what are
x |> f <| y
and
g <| x |> f "conflicting associativity" errors.
Right, in a similar situation GHCi says
Precedence parsing error cannot mix `foo' [infixl 9] and `bar' [infixr 9] in the same infix expression

On 18/04/2014, at 1:11 AM, Alexey Muranov wrote:
I do not know F#, and maybe i am missing something, but assuming that
x |> f |> g == (x |> f) |> g
and
g <| f <| x == g <| (f <| x)
what are
x |> f <| y
This is the same as (f x) y. Determined by experiment: let h x y = (x,y) ;; 1 |> h <| 2 ;; => val it : int * int = (1, 2) (f y) x would give the answer (2, 1).
g <| x |> f
This is f (g x). Determined by experiment: let f x = x * 2 ;; let g x = x + 1 ;; g <| 1 |> f ;; => val it : int = 4 g (f 1) would give the answer 3.
participants (7)
-
Alexander Berntsen
-
Alexey Muranov
-
Dan Burton
-
Erik Hesselink
-
Richard A. O'Keefe
-
Taylor Hedberg
-
Tony Morris