Is there an elegant notation for Currying the arguments of a function out of order in Haskell?
For example, if you wish to divide 2 by all elements of a list, you can write
map ((/) 2) [1,2,3,4,5]
However to divide all elements of a list it seems you need to define an anonymous function
map (\x -> x/2) [1,2,3,4,5]
Anonymous functions quickly become unwieldy in more complex cases. I’m aware that in this case map ((*) 0.5) [1,2,3,4,5] would work fine, but I’m interested to know if Haskell has a more elegant way of currying arguments of a function out of order?
In this particular case:
Not only you can use an infix operator as ordinary prefix function, you can also partially apply it in infix form. Likewise, the first example would better be written as
map (2/) [1..5]Also, there’s
flipwhich is not quite as elegant, but still the best option available for ordinary functions (when you don’t want to turn them into infix via backticks):