コード例 #1
0
        // Test with Recursive2
        private static void Test2()
        {
            Recursive2 <int, int> fibRec = f => n => n > 1 ? f(f)(n - 1) + f(f)(n - 2) : n;
            Func <int, int>       fib    = fibRec(fibRec);

            Console.WriteLine($"Wes Dyer: fib(6) = {fib(6)}"); // 8
        }
コード例 #2
0
        // Moving g outside
        private static void Test5()
        {
            Func <Func <int, int>, Func <int, int> > g = h => m => m > 1 ? h(m - 1) + h(m - 2) : m;
            Recursive2 <int, int> fibRec = f => n => g(f(f))(n);
            Func <int, int>       fib    = fibRec(fibRec);

            Console.WriteLine($"Wes Dyer: fib(6) = {fib(6)}"); // 8
        }
コード例 #3
0
        private static void Test3()
        {
            Recursive2 <int, int> fibRec = f => n =>
            {
                Func <Func <int, int>, int, int> g = (h, m) => m > 1 ? h(m - 1) + h(m - 2) : m;
                return(g(f(f), n));
            };
            Func <int, int> fib = fibRec(fibRec);

            Console.WriteLine($"Wes Dyer: fib(6) = {fib(6)}"); // 8
        }
コード例 #4
0
    public static void Test()
    {
        object x1 = new Recursive2 <int, int>(null);
        object x2 = new Mixed2 <int, int>(null, null, null);
        object x3 = new NonRecursive2 <int, int>(null);
        object x4 = new Expansive2 <int, int>(null);

        object y1 = new Recursive2 <string, string>(null);
        object y2 = new Mixed2 <string, string>(null, null, null);
        object y3 = new NonRecursive2 <string, string>(null);
        object y4 = new Expansive2 <string, string>(null);
    }
コード例 #5
0
 public Recursive2(Recursive2 <A, B> a1)
 {
     f1 = a1;
 }
コード例 #6
0
        // CreateFib
        static Func <int, int> CreateFib(Func <Func <int, int>, Func <int, int> > g)
        {
            Recursive2 <int, int> fibRec = f => n => g(f(f))(n);

            return(fibRec(fibRec));
        }
コード例 #7
0
        // Y
        private static Func <A, R> Y <A, R>(Func <Func <A, R>, Func <A, R> > f)
        {
            Recursive2 <A, R> rec = r => a => f(r(r))(a);

            return(rec(rec));
        }