1
Name:
Anonymous
2007-06-03 15:49
ID:xvzgDsaZ
public class Currier<ARG1, ARG2, RET> {
public interface CurriableFunctor<ARG1, ARG2, RET> {
RET evaluate(ARG1 arg1, ARG2 arg2);
}
public interface CurriedFunctor<ARG2, RET> {
RET evaluate(ARG2 arg);
}
final CurriableFunctor<ARG1, ARG2, RET> functor;
public Currier(CurriableFunctor<ARG1, ARG2, RET> fn) { functor = fn; }
public CurriedFunctor<ARG2, RET> curry(final ARG1 arg1) {
return new CurriedFunctor<ARG2, RET>() {
public RET evaluate(ARG2 arg2) {
return functor.evaluate(arg1, arg2);
}
};
}
public static void main(String[] args) {
Currier.CurriableFunctor<Integer, Integer, Integer> add
= new Currier.CurriableFunctor<Integer, Integer, Integer>() {
public Integer evaluate(Integer arg1, Integer arg2) {
return new Integer(arg1.intValue() + arg2.intValue());
}
};
Currier<Integer, Integer, Integer> currier
= new Currier<Integer, Integer, Integer>(add);
Currier.CurriedFunctor<Integer, Integer> add5
= currier.curry(new Integer(5));
System.out.println(add5.evaluate(new Integer(2)));
}
}
83
Name:
Anonymous
2008-11-10 0:28
MOLEST MY COMMA is now a meme
85
Name:
Anonymous
2008-11-10 14:50
>>39
You got me this time, anon!
90
Name:
je
2009-01-29 23:35
u saved my homework ! kool! hahaha thxs
91
Name:
Anonymous
2009-01-30 0:35
...and you said C# dont curry
using System;
namespace Currying
{
class Curried<T1, TResult>
{
Func<T1, TResult> func;
public Curried(Func<T1, TResult> f)
{
func = f;
}
public TResult Run(T1 t1)
{
return func(t1);
}
}
class Curried<T1, T2, TResult>
{
Func<T1, T2, TResult> func;
public Curried(Func<T1, T2, TResult> f)
{
func = f;
}
public Curried<T2, TResult> Run(T1 t1)
{
return new Curried<T2, TResult>(t2 => func(t1, t2));
}
public TResult Run(T1 t1, T2 t2)
{
return func(t1, t2);
}
}
class Curried<T1, T2, T3, TResult>
{
Func<T1, T2, T3, TResult> func;
public Curried(Func<T1, T2, T3, TResult> f)
{
func = f;
}
public Curried<T2, T3, TResult> Run(T1 t1)
{
return new Curried<T2, T3, TResult>((t2, t3) => func(t1, t2, t3));
}
public Curried<T3, TResult> Run(T1 t1, T2 t2)
{
return new Curried<T3, TResult>(t3 => func(t1, t2, t3));
}
public TResult Run(T1 t1, T2 t2, T3 t3)
{
return func(t1, t2, t3);
}
}
class Program
{
static int Add(int a, int b)
{
return a + b;
}
static int Add3(int a, int b, int c)
{
return a + b + c;
}
static void Main(string[] args)
{
var cAdd = new Curried<int, int, int>(Add);
var cAdd3 = new Curried<int, int, int, int>(Add3);
var added = cAdd.Run(5).Run(4);
var added3 = cAdd3.Run(1).Run(2).Run(3);
Console.WriteLine(added);
Console.WriteLine(added3);
}
}
}
...and you can continue writing more Curried<> classes like so.
94
Name:
Anonymous
2009-01-30 1:46
>>91
Needs more boost preprocessor metaprogramming.
97
Name:
Anonymous
2009-01-30 2:40
>>96
That's it, thread over everyone. Pack up your stuff and go home.
99
Name:
Anonymous
2009-03-06 8:21
Takes the creativity and imagination that an artist would have is on paper and what the hell You know I AM AN Enterprise Programmer I guarantee you it will be instructional.
101
Name:
Anonymous
2010-09-20 17:06
This was a great thread, besides the reddit faggots.
102
Name:
customs data
2011-08-05 2:35
Tradeinfo365 is a website that about exact, timely, and detailed global trade information,import and export data,the list of importers and exporters,customs data,supplier data.
http://www.tradeinfo365.com
http://www.tradeinfo365.com/page/TI365.html
http://www.tradeinfo365.com/page/Chinadata.html
103
Name:
Anonymous
2011-08-05 11:15
anonymous classes are cool in some ways and fucking stupid excuses for real lambdas in other ways. C# is superior, although inner classes would be a nice touch to it.
104
Name:
Anonymous
2011-08-05 14:37
>>,,,,,,,,,,,,,,,,,
Remember to
sage your posts for the benefit of all
/prog/ users.
108
Name:
Anonymous
2012-11-26 2:24
108th post for BAD CHINESE KARMA!