Talk:Partial function application: Difference between revisions
Content added Content deleted
(→Explicit curry vs Partial application: Anyone else up for it?) |
(The update is OK with me. Java solution.) |
||
Line 48: | Line 48: | ||
:::: Thanks Sonia. Anyone else OK with such an update? (Remember, the idea isn't to exclude Go; it is to more explicitely define partial application). --[[User:Paddy3118|Paddy3118]] 21:08, 13 April 2011 (UTC) |
:::: Thanks Sonia. Anyone else OK with such an update? (Remember, the idea isn't to exclude Go; it is to more explicitely define partial application). --[[User:Paddy3118|Paddy3118]] 21:08, 13 April 2011 (UTC) |
||
: The update is OK with me. |
|||
: I used <tt>(partial #'fs #'f1)</tt> to solve Common Lisp. I also solved Java. Java is a statically typed language, so the solution is like Ocaml or Haskell: I have to curry the <tt>fs()</tt> method. I start with this Java code. |
|||
: <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; |
|||
} |
|||
static int[] fsf1(int[] s) { |
|||
return fs(f1, s); |
|||
}</lang> |
|||
: This <tt>fsf1()</tt> explicitly curries <tt>fs()</tt>, mentions <tt>s</tt> and passes the return value from <tt>fs()</tt>. I change the code. |
|||
: <lang java>interface SequenceFunction { |
|||
int[] call(int[] arg); |
|||
} |
|||
static SequenceFunction fs(final IntegerFunction f) { |
|||
return new SequenceFunction() { |
|||
public int[] call(int[] s) { |
|||
int[] r = new int[s.length]; |
|||
for (int i = 0; i < s.length; i++) |
|||
r[i] = f.call(s[i]); |
|||
return r; |
|||
} |
|||
}; |
|||
} |
|||
static SequenceFunction fsf1 = fs(f1);</lang> |
|||
: This <tt>fs()</tt> explicitly curries ''itself''. So <tt>fsf1</tt> never has to mention <tt>s</tt> nor pass the return value from <tt>fs()</tt>. --[[User:Kernigh|Kernigh]] 20:26, 14 April 2011 (UTC) |