`flip` inline infix application arguments

For the infix function:

let fab = (a+10, b) f 4 5 => (14,5) 4 `f` 5 => (14,5) 

Arguments can be inverted by specifying an auxiliary 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

 (+10) `first` (7,8) (17,8) 

I would prefer a solution for a forward application, for example

 (7,8) `forwardFirst` (+10) 

without the need to write

 let forwardFirst = flip first 
+6
source share
1 answer

As described in detail in the HaskellWiki article on infix operators ,

Note that you can usually do this only with a function that takes two arguments. In fact, for a function that takes more than two arguments, you can do it, but it's not so nice

The way to do this in your case would be something like this:

 let fab = (a+10, b) let hab = (f `flip` a) b let a = 3 let b = 2 fab = (13,2) a `h` b = (12,3) 
+1
source

Source: https://habr.com/ru/post/978507/


All Articles