Given a function for infix usage:
let f a b = (a+10, b)
f 4 5
=> (14,5)
4 `f` 5
=> (14,5)
The arguments can be flipped by defining a helper function:
let g = flip f
4 `g` 5
=> (15,4)
Is it possible to do this inline?
4 `flip f` 5
=> parse error on input `f'
4 `(flip f)` 5
=> parse error on input `('
My use case is Control.Arrow.first
. Instead of
(+10) `first` (7,8)
(17,8)
I would prefer a forward-application-style solution like
(7,8) `forwardFirst` (+10)
without needing to write
let forwardFirst = flip first
As detailed in the HaskellWiki article on infix operators,
Note that you can only normally do this with a function that takes two arguments. Actually, for a function taking more than two arguments, you can do it but it's not nearly as nice
The way to do this in your case would be something like this:
let f a b = (a+10, b)
let h a b = (f `flip` a) b
let a = 3
let b = 2
f a b = (13,2)
a `h` b = (12,3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With