Talk:Partial function application: Difference between revisions

→‎Explicit curry vs Partial application: An attempt to compare Java, Haskell.
(→‎Explicit curry vs Partial application: An attempt to compare Java, Haskell.)
Line 86:
 
:: Hi Kernigh, the above is ''not'' like Haskel, in fact it doesn't really answer the task as you have made fs a function of only f, then called it with different f. Partial application would be like the Haskel: fs is a function of f ''and s'' and then fsfl is the result of applying only f1 to fs, without mention of any other argument. The above may give a result, but it is ''how'' it gets to that result that is the issue. --[[User:Paddy3118|Paddy3118]] 23:07, 14 April 2011 (UTC)
 
: I believed the description of the Haskell solution: "All functions actually take exactly one argument." I tried to do the same thing for Java: I wrote an ''fs()'' method that takes exactly one argument. The Java syntax is far worse than the Haskell syntax, but the result seems to be the same: ''fs'' takes exactly one parameter ''f'' and returns another function that takes exactly one parameter ''s''. When one says ''fs(arg1).call(arg2)'' in Java, then ''fs'' is a function of two parameters.
 
: One problem is that some program might already have ''fs(arg1, arg2)'', and I want to partially apply it. I might solve this by wrapping the method so I have both ''fs(arg1, arg2)'' and ''fs_curried(arg1).call(arg2)''. It might look like this.
 
: <lang java>static int[] fs(IntegerFunction f, int[] s) {
int[] r = new int[s.length];
for (int i = 0; i < s.length; i++)
r[i] = f.call(s[i]);
return r;
}
 
interface SequenceFunction {
int[] call(int[] arg);
}
 
static SequenceFunction fsCurried(final IntegerFunction f) {
return new SequenceFunction() {
public int[] call(int[] s) {
return fs(f, s);
}
};
}
 
static SequenceFunction fsf1 = fsCurried(f1);</lang>
 
: With the current solution for Java, ''fs(arg1).call(arg2)'' is already a function of two arguments, and there is no reason to also have ''fs(arg1, arg2)''.
 
: Haskell seems to have an analogy for ''fs(arg1, arg2)''. I looked around the Haskell 2010 report, and learned that Haskell has tuples. A function has only one parameter, but that parameter might be a tuple of 2 items. I also found these functions in the [http://www.haskell.org/onlinereport/haskell2010/haskellch9.html Haskell prelude]:
 
: <lang haskell>-- curry converts an uncurried function to a curried function;
-- uncurry converts a curried function to a function on pairs.
curry :: ((a, b) -> c) -> a -> b -> c
curry f x y = f (x, y)
 
uncurry :: (a -> b -> c) -> ((a, b) -> c)
uncurry f p = f (fst p) (snd p)</lang>
 
: It seems that one might define <tt>fs (f, s) = map f s</tt>, a function that takes a tuple and returns a sequence, then use <tt>curry fs f1</tt> as partial application. (There is no Haskell implementation on my computer, so I cannot test this. Perhaps I am wrong.) With the current solution for Haskell, ''fs arg1 arg2'' is already a function of two arguments, and there is no reason to also have ''fs (arg1, arg2)''.
 
: The current Java solution already solves the task: ''fs(arg1).call(arg2)'' is a function of two arguments, and ''fs(arg1)'' is a partial application. --[[User:Kernigh|Kernigh]] 02:15, 15 April 2011 (UTC)
 
==Is Scala correct?==
Anonymous user