I have to write a program that takes in an Integer and then uses two partial applications to first increment the number by one and then the second partial application doubles it. I know that a partial application would be one that would take less arguments than specified but each of these partial applications only needs 1 input. Does that mean I'm not passing anything into either of the partial applications? That really seems wrong/weird to me. Any help on where to start on the partial applications would be greatly appreciated
-
2It's not really clear what you want. Could you possibly write some pseudo-code to demonstrate the behavior you need? It might be that you're trying to solve the problem wrong, since a partially applied function is still a function, not an integer value. You seem to have noticed the confusion where you want to partially apply something of only one argument, so can you elaborate on your problem a bit more? – bheklilr Mar 16 '15 at 02:34
-
1Why did you remove the original problem text? – dfeuer Mar 16 '15 at 03:08
-
i was able to solve the question in the answer i submitted on the question. – Nived Mar 16 '15 at 03:15
-
@DevinHolland, your answer does not use partial application, and you still haven't answered my question. – dfeuer Mar 16 '15 at 03:19
-
@dfeur I'm not quite sure how you mean it's not using partial applications...each of the two functions double and addOne take an argument but i pass none in when i call them. – Nived Mar 16 '15 at 03:22
-
Eh, I guess technically *one* of them is partially applied (can you see which)? But so far the only reason I can see for removing the question text is to keep your teacher from finding it. – dfeuer Mar 16 '15 at 03:35
2 Answers
Your assignment is almost certainly asking you to use partial applications of something else to implement the "increment by one" and "double" operations. It's not asking you to partially apply those operations.
For example in the title of this very question you wrote "add 1" to mean your increment operation; isn't that just the partial application of an addition operation (which takes two operations) to a single argument (namely 1) to get a operation that takes only a single argument?

- 68,572
- 20
- 126
- 174
It sounds like you are supposed to use functions that take two arguments and partially apply them to arrive with the functions that take one argument. To increment a number by one using partial application, you might do something like this:
add a b = a + b
add_one = add 1
You take a function to add two numbers and partially apply it with one, so now you have a function that adds one to a number. The same principle applies to doubling.
multiply a b = a * b
double = multiply 2
The doubling function is just 2 partially applied to multiplication. To combine these, you can use function composition:
doubleIncr = multiply 2 . add 1
Hope this helps!

- 2,033
- 2
- 20
- 32
-
So how can i run them both in sequence...like partially apply add and multiply in one function? – Nived Mar 16 '15 at 02:43
-
-
You can just apply both of the new function to a value, like `double ( add_one 2)` to apply it to the value 2. If you wanted to create a function to do these in sequence, you could use function composition, like this: `increment_double = double . add_one` That notation created a new function that sequences the functions separated by periods from right to left. – charleyh Mar 16 '15 at 02:44
-
@zerkms Currently am using doubleIncr = multiply . add 1 and it gives me an error – Nived Mar 16 '15 at 02:47
-
@DevinHolland You'll need to partially apply the 2 to the multiply also, like this (assuming you have already defined add and multiply): `doubleIncr = multiply 2 . add 1` – charleyh Mar 16 '15 at 02:50
-
@charleyh do i have to use two parameters for them? Could I just use double . addOne with double and addOne just taking 1 parameter and adding 1 to it and similar for double? – Nived Mar 16 '15 at 03:25
-
@DevinHolland yep, `doubleIncr = double . addOne` works fine, assuming that you already define double and addOne. Using `doubleIncr = multiply 2 . add 1` just might be less verbose if you won't need to use a doubling or incrementing function on its own again – charleyh Mar 16 '15 at 03:28
-
@charleyh yeah this is just for one question in an assignment...not going to be reused ever. i defined `double a = a *2 and addOne a = a + 1 ` – Nived Mar 16 '15 at 03:29
-
@DevinHolland Although those are functionally the same, that isn't actually partial application, so if its for an assignment, it might be considered wrong. You need to actually define a function like `addOne = (+1)` for it to be partially applied. – charleyh Mar 16 '15 at 03:32