WeixiangYan/CodeTransOcean huggingface dataset:
Task: Bernoulli numbers



C#: using Mpir.NET;
using System;

namespace Bernoulli
{
    class Program
    {
        private static void bernoulli(mpq_t rop, uint n)
        {
            mpq_t[] a = new mpq_t[n + 1];

            for (uint i = 0; i < n + 1; i++)
            {
                a[i] = new mpq_t();
            }

            for (uint m = 0; m <= n; ++m)
            {
                mpir.mpq_set_ui(a[m], 1, m + 1);

                for (uint j = m; j > 0; --j)
                {
                    mpir.mpq_sub(a[j - 1], a[j], a[j - 1]);
                    mpir.mpq_set_ui(rop, j, 1);
                    mpir.mpq_mul(a[j - 1], a[j - 1], rop);
                }

                mpir.mpq_set(rop, a[0]);
            }
        }

        static void Main(string[] args)
        {
            mpq_t rop = new mpq_t();
            mpz_t n = new mpz_t();
            mpz_t d = new mpz_t();

            for (uint  i = 0; i <= 60; ++i) 
            {
                bernoulli(rop, i);

                if (mpir.mpq_cmp_ui(rop, 0, 1) != 0) 
                {
                    mpir.mpq_get_num(n, rop);
                    mpir.mpq_get_den(d, rop);
                    Console.WriteLine(string.Format("B({0, 2}) = {1, 44} / {2}", i, n, d));
                }
            }

            Console.ReadKey();
        }
    }
}





Python: from fractions import Fraction as Fr

def bernoulli(n):
    A = [0] * (n+1)
    for m in range(n+1):
        A[m] = Fr(1, m+1)
        for j in range(m, 0, -1):
          A[j-1] = j*(A[j-1] - A[j])
    return A[0] 

bn = [(i, bernoulli(i)) for i in range(61)]
bn = [(i, b) for i,b in bn if b]
width = max(len(str(b.numerator)) for i,b in bn)
for i,b in bn:
    print('B(%2i) = %*i/%i' % (i, width, b.numerator, b.denominator))
Task: Bernoulli numbers



C#: using Mpir.NET;
using System;

namespace Bernoulli
{
    class Program
    {
        private static void bernoulli(mpq_t rop, uint n)
        {
            mpq_t[] a = new mpq_t[n + 1];

            for (uint i = 0; i < n + 1; i++)
            {
                a[i] = new mpq_t();
            }

            for (uint m = 0; m <= n; ++m)
            {
                mpir.mpq_set_ui(a[m], 1, m + 1);

                for (uint j = m; j > 0; --j)
                {
                    mpir.mpq_sub(a[j - 1], a[j], a[j - 1]);
                    mpir.mpq_set_ui(rop, j, 1);
                    mpir.mpq_mul(a[j - 1], a[j - 1], rop);
                }

                mpir.mpq_set(rop, a[0]);
            }
        }

        static void Main(string[] args)
        {
            mpq_t rop = new mpq_t();
            mpz_t n = new mpz_t();
            mpz_t d = new mpz_t();

            for (uint  i = 0; i <= 60; ++i) 
            {
                bernoulli(rop, i);

                if (mpir.mpq_cmp_ui(rop, 0, 1) != 0) 
                {
                    mpir.mpq_get_num(n, rop);
                    mpir.mpq_get_den(d, rop);
                    Console.WriteLine(string.Format("B({0, 2}) = {1, 44} / {2}", i, n, d));
                }
            }

            Console.ReadKey();
        }
    }
}






VB: 
Imports System.Numerics 

Module Bernoulli_numbers

    Function gcd_BigInt(ByVal x As BigInteger, ByVal y As BigInteger) As BigInteger
        Dim y2 As BigInteger
        x = BigInteger.Abs(x)
        Do
            y2 = BigInteger.Remainder(x, y)
            x = y
            y = y2
        Loop Until y = 0
        Return x
    End Function 

    Sub bernoul_BigInt(n As Integer, ByRef bnum As BigInteger, ByRef bden As BigInteger)
        Dim j, m As Integer
        Dim f As BigInteger
        Dim anum(), aden() As BigInteger
        ReDim anum(n + 1), aden(n + 1)
        For m = 0 To n
            anum(m + 1) = 1
            aden(m + 1) = m + 1
            For j = m To 1 Step -1
                anum(j) = j * (aden(j + 1) * anum(j) - aden(j) * anum(j + 1))
                aden(j) = aden(j) * aden(j + 1)
                f = gcd_BigInt(BigInteger.Abs(anum(j)), BigInteger.Abs(aden(j)))
                If f <> 1 Then
                    anum(j) = anum(j) / f
                    aden(j) = aden(j) / f
                End If
            Next
        Next
        bnum = anum(1) : bden = aden(1)
    End Sub 

    Sub bernoulli_BigInt()
        Dim i As Integer
        Dim bnum, bden As BigInteger
        bnum = 0 : bden = 0
        For i = 0 To 60
            bernoul_BigInt(i, bnum, bden)
            If bnum <> 0 Then
                Console.WriteLine("B(" & i & ")=" & bnum.ToString("D") & "/" & bden.ToString("D"))
            End If
        Next i
    End Sub 
    
End Module
Task: Bernoulli numbers





Java: import org.apache.commons.math3.fraction.BigFraction;

public class BernoulliNumbers {

    public static void main(String[] args) {
        for (int n = 0; n <= 60; n++) {
            BigFraction b = bernouilli(n);
            if (!b.equals(BigFraction.ZERO))
                System.out.printf("B(%-2d) = %-1s%n", n , b);
        }
    }

    static BigFraction bernouilli(int n) {
        BigFraction[] A = new BigFraction[n + 1];
        for (int m = 0; m <= n; m++) {
            A[m] = new BigFraction(1, (m + 1));
            for (int j = m; j >= 1; j--)
                A[j - 1] = (A[j - 1].subtract(A[j])).multiply(new BigFraction(j));
        }
        return A[0];
    }
}



Python: from fractions import Fraction as Fr

def bernoulli(n):
    A = [0] * (n+1)
    for m in range(n+1):
        A[m] = Fr(1, m+1)
        for j in range(m, 0, -1):
          A[j-1] = j*(A[j-1] - A[j])
    return A[0] 

bn = [(i, bernoulli(i)) for i in range(61)]
bn = [(i, b) for i,b in bn if b]
width = max(len(str(b.numerator)) for i,b in bn)
for i,b in bn:
    print('B(%2i) = %*i/%i' % (i, width, b.numerator, b.denominator))
Task: Bernoulli numbers





Java: import org.apache.commons.math3.fraction.BigFraction;

public class BernoulliNumbers {

    public static void main(String[] args) {
        for (int n = 0; n <= 60; n++) {
            BigFraction b = bernouilli(n);
            if (!b.equals(BigFraction.ZERO))
                System.out.printf("B(%-2d) = %-1s%n", n , b);
        }
    }

    static BigFraction bernouilli(int n) {
        BigFraction[] A = new BigFraction[n + 1];
        for (int m = 0; m <= n; m++) {
            A[m] = new BigFraction(1, (m + 1));
            for (int j = m; j >= 1; j--)
                A[j - 1] = (A[j - 1].subtract(A[j])).multiply(new BigFraction(j));
        }
        return A[0];
    }
}




VB: 
Imports System.Numerics 

Module Bernoulli_numbers

    Function gcd_BigInt(ByVal x As BigInteger, ByVal y As BigInteger) As BigInteger
        Dim y2 As BigInteger
        x = BigInteger.Abs(x)
        Do
            y2 = BigInteger.Remainder(x, y)
            x = y
            y = y2
        Loop Until y = 0
        Return x
    End Function 

    Sub bernoul_BigInt(n As Integer, ByRef bnum As BigInteger, ByRef bden As BigInteger)
        Dim j, m As Integer
        Dim f As BigInteger
        Dim anum(), aden() As BigInteger
        ReDim anum(n + 1), aden(n + 1)
        For m = 0 To n
            anum(m + 1) = 1
            aden(m + 1) = m + 1
            For j = m To 1 Step -1
                anum(j) = j * (aden(j + 1) * anum(j) - aden(j) * anum(j + 1))
                aden(j) = aden(j) * aden(j + 1)
                f = gcd_BigInt(BigInteger.Abs(anum(j)), BigInteger.Abs(aden(j)))
                If f <> 1 Then
                    anum(j) = anum(j) / f
                    aden(j) = aden(j) / f
                End If
            Next
        Next
        bnum = anum(1) : bden = aden(1)
    End Sub 

    Sub bernoulli_BigInt()
        Dim i As Integer
        Dim bnum, bden As BigInteger
        bnum = 0 : bden = 0
        For i = 0 To 60
            bernoul_BigInt(i, bnum, bden)
            If bnum <> 0 Then
                Console.WriteLine("B(" & i & ")=" & bnum.ToString("D") & "/" & bden.ToString("D"))
            End If
        Next i
    End Sub 
    
End Module
Task: Bernoulli numbers







Python: from fractions import Fraction as Fr

def bernoulli(n):
    A = [0] * (n+1)
    for m in range(n+1):
        A[m] = Fr(1, m+1)
        for j in range(m, 0, -1):
          A[j-1] = j*(A[j-1] - A[j])
    return A[0] 

bn = [(i, bernoulli(i)) for i in range(61)]
bn = [(i, b) for i,b in bn if b]
width = max(len(str(b.numerator)) for i,b in bn)
for i,b in bn:
    print('B(%2i) = %*i/%i' % (i, width, b.numerator, b.denominator))


VB: 
Imports System.Numerics 

Module Bernoulli_numbers

    Function gcd_BigInt(ByVal x As BigInteger, ByVal y As BigInteger) As BigInteger
        Dim y2 As BigInteger
        x = BigInteger.Abs(x)
        Do
            y2 = BigInteger.Remainder(x, y)
            x = y
            y = y2
        Loop Until y = 0
        Return x
    End Function 

    Sub bernoul_BigInt(n As Integer, ByRef bnum As BigInteger, ByRef bden As BigInteger)
        Dim j, m As Integer
        Dim f As BigInteger
        Dim anum(), aden() As BigInteger
        ReDim anum(n + 1), aden(n + 1)
        For m = 0 To n
            anum(m + 1) = 1
            aden(m + 1) = m + 1
            For j = m To 1 Step -1
                anum(j) = j * (aden(j + 1) * anum(j) - aden(j) * anum(j + 1))
                aden(j) = aden(j) * aden(j + 1)
                f = gcd_BigInt(BigInteger.Abs(anum(j)), BigInteger.Abs(aden(j)))
                If f <> 1 Then
                    anum(j) = anum(j) / f
                    aden(j) = aden(j) / f
                End If
            Next
        Next
        bnum = anum(1) : bden = aden(1)
    End Sub 

    Sub bernoulli_BigInt()
        Dim i As Integer
        Dim bnum, bden As BigInteger
        bnum = 0 : bden = 0
        For i = 0 To 60
            bernoul_BigInt(i, bnum, bden)
            If bnum <> 0 Then
                Console.WriteLine("B(" & i & ")=" & bnum.ToString("D") & "/" & bden.ToString("D"))
            End If
        Next i
    End Sub 
    
End Module
Task: Bernoulli numbers


C++: 

#include <boost/multiprecision/cpp_int.hpp>  
#include <boost/rational.hpp>                
#include <iostream>                          
#include <vector>                            

typedef boost::rational<boost::multiprecision::int1024_t> rational;  

rational bernoulli(size_t n) {
    auto out = std::vector<rational>();

    for (size_t m = 0; m <= n; m++) {
        out.emplace_back(1, (m + 1));  
        for (size_t j = m; j >= 1; j--) {
            out[j - 1] = rational(j) * (out[j - 1] - out[j]);
        }
    }
    return out[0];
}

int main() {
    for (size_t n = 0; n <= 60; n += n >= 2 ? 2 : 1) {
        auto b = bernoulli(n);
        std::cout << "B(" << std::right << std::setw(2) << n << ") = ";
        std::cout << std::right << std::setw(44) << b.numerator();
        std::cout << " / " << b.denominator() << std::endl;
    }

    return 0;
}


C#: using Mpir.NET;
using System;

namespace Bernoulli
{
    class Program
    {
        private static void bernoulli(mpq_t rop, uint n)
        {
            mpq_t[] a = new mpq_t[n + 1];

            for (uint i = 0; i < n + 1; i++)
            {
                a[i] = new mpq_t();
            }

            for (uint m = 0; m <= n; ++m)
            {
                mpir.mpq_set_ui(a[m], 1, m + 1);

                for (uint j = m; j > 0; --j)
                {
                    mpir.mpq_sub(a[j - 1], a[j], a[j - 1]);
                    mpir.mpq_set_ui(rop, j, 1);
                    mpir.mpq_mul(a[j - 1], a[j - 1], rop);
                }

                mpir.mpq_set(rop, a[0]);
            }
        }

        static void Main(string[] args)
        {
            mpq_t rop = new mpq_t();
            mpz_t n = new mpz_t();
            mpz_t d = new mpz_t();

            for (uint  i = 0; i <= 60; ++i) 
            {
                bernoulli(rop, i);

                if (mpir.mpq_cmp_ui(rop, 0, 1) != 0) 
                {
                    mpir.mpq_get_num(n, rop);
                    mpir.mpq_get_den(d, rop);
                    Console.WriteLine(string.Format("B({0, 2}) = {1, 44} / {2}", i, n, d));
                }
            }

            Console.ReadKey();
        }
    }
}
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}



C#: String s = new String('X', 5);
s.Replace("X", "ha");
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}







Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}








VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Repeat a string



C#: String s = new String('X', 5);
s.Replace("X", "ha");



Java: String funny = "ha" * 5;
String stars = '*' * 80;
Task: Repeat a string



C#: String s = new String('X', 5);
s.Replace("X", "ha");





Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times
Task: Repeat a string





Java: String funny = "ha" * 5;
String stars = '*' * 80;




VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Repeat a string




Go: fmt.Println(strings.Repeat("ha", 5))        




Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times
Task: Repeat a string




Go: fmt.Println(strings.Repeat("ha", 5))        





VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Repeat a string







Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times


VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Repeat a string





Java: String funny = "ha" * 5;
String stars = '*' * 80;



Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}




Go: fmt.Println(strings.Repeat("ha", 5))
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}





Java: String funny = "ha" * 5;
String stars = '*' * 80;
Task: Repeat a string



C#: String s = new String('X', 5);
s.Replace("X", "ha");






VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Repeat a string

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * string_repeat( int n, const char * s ) {
  size_t slen = strlen(s);
  char * dest = malloc(n*slen+1);

  int i; char * p;
  for ( i=0, p = dest; i < n; ++i, p += slen ) {
    memcpy(p, s, slen);
  }
  *p = '\0';
  return dest;
}

int main() {
  char * result = string_repeat(5, "ha");
  puts(result);
  free(result);
  return 0;
}






PHP: str_repeat("ha", 5)
Task: Repeat a string






PHP: str_repeat("ha", 5)


Python: def setup():
    rep = repeat("ha", 5)
    println(rep)

def repeat(s, times):
    return s * times
Task: Repeat a string






PHP: str_repeat("ha", 5)



VB: 
showmessage String$(10, "-")


function Repeat$(Expr as string, Count as integer) as string
    dim x as integer
    for x = 1 to Count
        Result = Result + Expr
    next
end function

showmessage Repeat$("ha", 5)
Task: Currying

C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}



C#: public delegate int Plus(int y); 
public delegate Plus CurriedPlus(int x);
public static CurriedPlus plus = 
      delegate(int x) {return delegate(int y) {return x + y;};};
static void Main()
{
    int sum = plus(3)(4); 
    int sum2= plus(2)(plus(3)(4)) 
}
Task: Currying

C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}





Java: module CurryPower
    {
    @Inject Console console;
    void run()
        {
        function Int(Int, Int) divide = (x,y) -> x / y;

        function Int(Int) half = divide(_, 2);
        function Int(Int) partsOf120 = divide(120, _);

        console.print($|half of a dozen is {half(12)}
                       |half of 120 is {partsOf120(2)}
                       |a third is {partsOf120(3)}
                       |and a quarter is {partsOf120(4)}
                     );
        }
    }
Task: Currying

C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}







Python:  def addN(n):
     def adder(x):
         return x + n
     return adder
Task: Currying

C: #include<stdarg.h>
#include<stdio.h>

long int factorial(int n){
	if(n>1)
		return n*factorial(n-1);
	return 1;
}

long int sumOfFactorials(int num,...){
	va_list vaList;
	long int sum = 0;
	
	va_start(vaList,num);
	
	while(num--)
		sum += factorial(va_arg(vaList,int));
	
	va_end(vaList);
	
	return sum;
}

int main()
{
	printf("\nSum of factorials of [1,5] : %ld",sumOfFactorials(5,1,2,3,4,5));
	printf("\nSum of factorials of [3,5] : %ld",sumOfFactorials(3,3,4,5));
	printf("\nSum of factorials of [1,3] : %ld",sumOfFactorials(3,1,2,3));
	
	return 0;
}








VB: Option Explicit On
Option Infer On
Option Strict On

Module Currying
    
    Function Curry(Of T1, TResult)(func As Func(Of T1, TResult)) As Func(Of T1, TResult)
        
        Return Function(a) func(a)
    End Function

    Function Curry(Of T1, T2, TResult)(func As Func(Of T1, T2, TResult)) As Func(Of T1, Func(Of T2, TResult))
        Return Function(a) Function(b) func(a, b)
    End Function

    Function Curry(Of T1, T2, T3, TResult)(func As Func(Of T1, T2, T3, TResult)) As Func(Of T1, Func(Of T2, Func(Of T3, TResult)))
        Return Function(a) Function(b) Function(c) func(a, b, c)
    End Function

    
End Module
Task: Currying



C#: public delegate int Plus(int y); 
public delegate Plus CurriedPlus(int x);
public static CurriedPlus plus = 
      delegate(int x) {return delegate(int y) {return x + y;};};
static void Main()
{
    int sum = plus(3)(4); 
    int sum2= plus(2)(plus(3)(4)) 
}


Go: package main

import (
        "fmt"
        "math"
)

func PowN(b float64) func(float64) float64 {
        return func(e float64) float64 { return math.Pow(b, e) }
}

func PowE(e float64) func(float64) float64 {
        return func(b float64) float64 { return math.Pow(b, e) }
}

type Foo int

func (f Foo) Method(b int) int {
        return int(f) + b
}

func main() {
        pow2 := PowN(2)
        cube := PowE(3)

        fmt.Println("2^8 =", pow2(8))
        fmt.Println("4³ =", cube(4))

        var a Foo = 2
        fn1 := a.Method   
        fn2 := Foo.Method 

        fmt.Println("2 + 2 =", a.Method(2)) 
        fmt.Println("2 + 3 =", fn1(3))
        fmt.Println("2 + 4 =", fn2(a, 4))
        fmt.Println("3 + 5 =", fn2(Foo(3), 5))
}
Task: Currying



C#: public delegate int Plus(int y); 
public delegate Plus CurriedPlus(int x);
public static CurriedPlus plus = 
      delegate(int x) {return delegate(int y) {return x + y;};};
static void Main()
{
    int sum = plus(3)(4); 
    int sum2= plus(2)(plus(3)(4)) 
}



Java: module CurryPower
    {
    @Inject Console console;
    void run()
        {
        function Int(Int, Int) divide = (x,y) -> x / y;

        function Int(Int) half = divide(_, 2);
        function Int(Int) partsOf120 = divide(120, _);

        console.print($|half of a dozen is {half(12)}
                       |half of 120 is {partsOf120(2)}
                       |a third is {partsOf120(3)}
                       |and a quarter is {partsOf120(4)}
                     );
        }
    }
Task: Currying



C#: public delegate int Plus(int y); 
public delegate Plus CurriedPlus(int x);
public static CurriedPlus plus = 
      delegate(int x) {return delegate(int y) {return x + y;};};
static void Main()
{
    int sum = plus(3)(4); 
    int sum2= plus(2)(plus(3)(4)) 
}





Python:  def addN(n):
     def adder(x):
         return x + n
     return adder