3 ms·
Neither 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 redundan
by whilenot-dev 3y ago
Neither 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 agoI'm happy that you spent a wonderful day outdoors! Do you think that makes your statement "Currying is a subset of partial application" (and doubling down on that) any more true? After all, you can implement subtraction with just the help of addition and multiplication: add :: Int -> Int -> Int add a b = a + b mult :: Int -> Int -> Int mult a b = a * b sub :: Int -> Int -> Int sub a b = add a (mult (-1) b) So, does that make "subtraction is a subset of addition" a true statement?
- kerkeslager 3y agoYes. Why not? Would you be confused about what someone meant if they said that statement? My critique of your original post is that you're treating English like it's a computer language where words mean very specific things. But the reality is that English is a cobbled-together bunch of words with imprecise meanings that arise from common usage. Let me reiterate: usage determines meaning, not the other way around. You're approaching this conversation with your own preconceived notions about what the words mean and trying to force your preconceived notions onto everyone else instead of trying to understand what the other person means. It's a rude way to treat people trying to communicate with you. I mean, it's clear that you understand the idea because you're coming up with examples that show that you understand it. Communication was successful. There's no problem with the communication. The problem is that you decided, after communication was successful, to force your preferred usage of the words on other people. This is an extremely common interpersonal mistake that technical people make because unlike English, computer languages have very specific, objective meanings. But expecting that same objective specificity from humans speaking English isn't realistic, kind, or polite. It's one of the main reasons technical people are widely perceived as socially inept. Behaving like this hurts our careers, friendships, and romantic relationships. Doing this on HN is just a minor annoyance to everyone else, but if you do this in your life as a whole, the person you're harming most is yourself, because you're making it a pain in the ass to communicate with you. I'm asking you to be a better reader and listener. And look, maybe you can get skybrian or me to change the way we communicate to suit your preferences, but why? Nothing is gained. And if you spend your life trying to force people to communicate a certain way instead of trying to understand people, it's just going to be an endless war, where the only meaningful result you'll achieve is that it's harder for people to communicate with you. Is that what you want for yourself? If you'd approached this from the perspective of "hey I think people would understand you better if you said it this other way", that would be fine. I think it's great to improve communication, and it's both up to speaker/writer and listener/reader to meet in the middle: both sides of this interaction can improve. But that's a pretty big difference between coming at someone like "you're wrong".