J8SKY

Sep. 21st, 2016 01:16 am
xacid: (Default)
public interface Fn<A, B> {
    B apply(A a);

    static <X> Fn<X, X> I() {
        return x -> x;
    }

    // Kxy = x

    static <X, Y> Fn<X, Fn<Y, X>> K() {
        return x -> y -> x;
    }

    // Sxyz = xz(yz)

    static <X, Y, Z> Fn<Fn<Z, Fn<Y, X>>,
            Fn<Fn<Z, Y>, Fn<Z, X>>> S() {
        return x -> y -> z ->
                x.apply(z).apply(y.apply(z));
    }

    // Yf=f(Yf)

    interface Y<A> extends Fn<Y<A>, Fn<A, A>> {
        static <A> Y<A> Y() {
            return f -> f.apply(f);
        }
    }

    static <A> Fn<Fn<Fn<A, A>,
            Fn<A, A>>, Fn<A, A>> Y() {
        return g -> Y.<A>Y().apply(f ->
                g.apply(x -> f.apply(f).apply(x)));
    }
}

Profile

xacid: (Default)
xacid

August 2017

S M T W T F S
  123 45
67891011 12
13 141516171819
20212223242526
2728293031  

Syndicate

RSS Atom

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 19th, 2017 05:03 pm
Powered by Dreamwidth Studios