Given the following function f with two arguments, what is the standard way to apply a map only to x?
A little discussion of currying and partial use
In terms of FP, your function f "uncurried" - although it conceptually takes two arguments, they are combined into a single product structure. In Python, everything is careless, all the time. You must immediately give all the arguments, or none of them.
There are various tricks to get around this, but conceptually you just want a curry function. That is, convert f(x,y) to f(x) , which returns a new function g(y) .
In languages ββthat have a default value, you can easily write this translation as:
-- curry: take a function from (x,y) to one from x to a function from y to z curry :: ((x,y) -> z) -> (x -> y -> z) curry fxy = f (x, y)
So, curry takes your curried f and its product arguments separately and applies the arguments when they are all available. The opposite is also quite simple:
uncurry :: (x -> y -> z) -> ((x,y) -> z) uncurry f (x,y) = fxy
How does this relate to partial applications?
- Currying takes a function that takes a 1 (n-product) argument structure and returns a new function that takes n arguments.
- A partial application takes a function of n arguments and applies them to k arguments, providing the function nk of the remaining arguments.
In an unidentified language, each of the arguments can be applied alternately (for example, partially in relation to the arity of the function). In black, you need to play some tricks to align the function first, as in the examples above.
I think itβs more flexible to be in the environment with the default map, since the partial application is free. In such an environment, functions that change the structure of the data into the pipeline are usually combined. For example. conveyor of whole modifications:
(+1) . (*2) . (^3) $ 7
- this is just a chain of partially applied, unprocessed functions, each of which works at the output of the previous function. This can be nice, as it visually separates the problems.