3 ms·
> ...can you understand how "Currying is a subset of partial application" is true? It isn't true and i can understand why someone would make that statement. Cu
by whilenot-dev 3y ago
> ...can you understand how "Currying is a subset of partial application" is true?
It isn't true and i can understand why someone would make that statement. Currying and partial application both come from a functional mindset that treats functions as data, and like data also functions can be transformed.
Currying and partial application both satisfy a transformation depending on a desired context:
- Currying "widens" a function "up" (as in you don't need to know all arguments beforehand in the same context anymore)
- Partial application "narrows" a function "down" (as in arguments are contained within the context of the partially applied function)
"Currying is a subset of partial application" is true in the same sense as if "subtraction is a subset of addition". Sure, you can subtract negative values to have addition and add negative values to have subtraction, but that can't be your point, is it?
> If you take a step back and resist the urge to correct people...
Please keep it on topic.
- kerkeslager 3y ago> It isn't true and i can understand why someone would make that statement It is true, and you are smart enough to understand it if you stop assuming you're the only one who understands the topic. I'm specifically sticking with the wording "Currying is a subset of partial application" to make the point that you can understand what someone is trying to say even if they don't say it exactly the way you would like them to say it. > - Currying "widens" a function "up" (as in you don't need to know all arguments beforehand in the same context anymore) > - Partial application "narrows" a function "down" (as in arguments are contained within the context of the partially applied function) So you're saying that I'm "widening" the function "up" when I do: increment = add 1 invert = div 1 ...? But I'm "narrowing" the function "down" when I do: increment = (\x -> add 1 x) halve = (\x -> div x 2) ...? When I curry `add` above, isn't the argument 1 contained within the context of the partially applied function? When I partially apply `div` above, don't I no longer have to know all the arguments (i.e. I no longer need to know the denominator 2)? It sure seems like this up/down wide/narrow wording you're fixated on isn't a particularly better descriptions of what's going on with currying and partial application. It mean, maybe it's just my font, but the partial applications are a bit wider on my screen. ;P > "Currying is a subset of partial application" is true in the same sense as if "subtraction is a subset of addition". Sure, you can subtract negative values to have addition and add negative values to have subtraction, but that can't be your point, is it? I'm not sure I understand that analogy to say it's my point. Are you saying you would behave condescendingly toward someone who said "subtraction is a subset of addition" too? > Please keep it on topic. The topic skybrian started was derailed when you decided to "correct" him because you didn't make any effort to understand what he was trying to say. Your behavior is the topic now because your behavior became a problem.
- whilenot-dev 3y agoNeither of your examples does curry a function. The first one partially applies it (the Haskell way), the second one wraps the partial application in a redundant lambda (Haskell again). I think that's where the confusion is, let me also try to use the Haskell syntax... This is an add function with two arguments: add :: (Int, Int) -> Int add (x, y) = x + y At the moment it can not be partially applied, so let's curry it: -- addCurr :: Int -> Int -> Int addCurr = curry add Now let's partially apply it for an increment function: -- increment :: Int -> Int increment = addCurr 1 > When I curry `add` above, isn't the argument 1 contained within the context of the partially applied function? You didn't curry it, you partially applied it. This was possible, because your function add was already curried.
- kerkeslager 3y agoOkay, that's a fair critique, let it not be said I can't admit when I'm wrong. I shouldn't have used `curry` as a verb there, as my point was about the concept of currying rather than the specific curry function. My mistake there doesn't negate my larger point, but I've gotta go touch grass.
- kerkeslager 3y agoComing back to this having spent a wonderful day outdoors. Okay, writing this in Python because a) it's been a while since I wrote Haskell, b) it will let other readers read the code more easily, and c) Python clearly denotes what a partial is by having a `partial` function: from inspect import signature from functools import partial def curry(f, parameters=None): if parameters is None: parameters = list(signature(f).parameters.keys()) if len(parameters) == 0: return f head = parameters[0] tail = parameters[1:] # I draw your attention to this line return lambda p: curry(partial(f, **{head: p}), tail) def divide(a, b, c): return a / b / c curried_divide = curry(divide) # prints "3" print(curried_divide(30)(5)(2)()) So... curry can be implemented in terms of partial applications, no?
- whilenot-dev 3y ago