Created
October 27, 2012 19:17
-
-
Save pelotom/3965741 to your computer and use it in GitHub Desktop.
Muahahaha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavaGenTest { | |
public static interface F<a, b> { | |
b f(a a); | |
} | |
public static abstract class P2<a, b> { | |
private static final class _P2<a, b> extends P2<a, b> { | |
private final a _1; | |
private final b _2; | |
private _P2(final a _1, final b _2) { | |
this._1 = _1; | |
this._2 = _2; | |
} | |
public <M> M match(final F<a, F<b, M>> ifP2) { | |
return ifP2.f(_1).f(_2); | |
} | |
} | |
public abstract <M> M match(final F<a, F<b, M>> ifP2); | |
} | |
public static abstract class List<a> { | |
private static final class _Nil<a> extends List<a> { | |
private _Nil() { | |
} | |
public <M> M match(final M ifNil, final F<a, F<List<a>, M>> ifCons) { | |
return ifNil; | |
} | |
} | |
private static final class _Cons<a> extends List<a> { | |
private final a _1; | |
private final List<a> _2; | |
private _Cons(final a _1, final List<a> _2) { | |
this._1 = _1; | |
this._2 = _2; | |
} | |
public <M> M match(final M ifNil, final F<a, F<List<a>, M>> ifCons) { | |
return ifCons.f(_1).f(_2); | |
} | |
} | |
public abstract <M> M match(final M ifNil, final F<a, F<List<a>, M>> ifCons); | |
} | |
public static final <a, b> F<a, F<b, P2<a, b>>> P2(final a _a, final b _b) { | |
return new F<a, F<b, P2<a, b>>>() { | |
public F<b, P2<a, b>> f(final a _1) { | |
return new F<b, P2<a, b>>() { | |
public P2<a, b> f(final b _2) { | |
return new P2._P2<a, b>(_1, _2); | |
} | |
}; | |
} | |
}; | |
} | |
public static final <a> List<a> Nil(final a _a) { | |
return new List._Nil<a>(); | |
} | |
public static final <a> F<a, F<List<a>, List<a>>> Cons(final a _a) { | |
return new F<a, F<List<a>, List<a>>>() { | |
public F<List<a>, List<a>> f(final a _1) { | |
return new F<List<a>, List<a>>() { | |
public List<a> f(final List<a> _2) { | |
return new List._Cons<a>(_1, _2); | |
} | |
}; | |
} | |
}; | |
} | |
public static final <a, b, c> F<F<a, F<b, c>>, F<List<a>, F<List<b>, List<c>>>> zipWith(final a _a, final b _b, final c _c) { | |
return new F<F<a, F<b, c>>, F<List<a>, F<List<b>, List<c>>>>() { | |
public F<List<a>, F<List<b>, List<c>>> f(final F<a, F<b, c>> f) { | |
return new F<List<a>, F<List<b>, List<c>>>() { | |
public F<List<b>, List<c>> f(final List<a> xs) { | |
return new F<List<b>, List<c>>() { | |
public List<c> f(final List<b> ys) { | |
return (xs).match(Nil((c) null), new F<a, F<List<a>, List<c>>>() { | |
public F<List<a>, List<c>> f(final a x) { | |
return new F<List<a>, List<c>>() { | |
public List<c> f(final List<a> xs) { | |
return (ys).match(Nil((c) null), new F<b, F<List<b>, List<c>>>() { | |
public F<List<b>, List<c>> f(final b y) { | |
return new F<List<b>, List<c>>() { | |
public List<c> f(final List<b> ys) { | |
return Cons((c) null).f(f.f(x).f(y)).f( | |
zipWith((a) null, (b) null, (c) null).f(f).f(xs).f(ys)); | |
} | |
}; | |
} | |
}); | |
} | |
}; | |
} | |
}); | |
} | |
}; | |
} | |
}; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment