Skip to content

Instantly share code, notes, and snippets.

@numa08
Created June 22, 2012 16:39
Show Gist options
  • Save numa08/2973904 to your computer and use it in GitHub Desktop.
Save numa08/2973904 to your computer and use it in GitHub Desktop.
C#とScalaで関数型言語プログラミング ref: http://qiita.com/items/0ffb676dcf0afff5d78b
class Program
{
static void Main(string[] args)
{
loopCall(10, nTimes(5));
}
static void loopCall(int max, Func<int, int> func)
{
for (int i = 1; i < max+1; i++)
{
Console.Write(func(i) + " ");
}
}
static Func<int, int> nTimes(int times)
{
return n => n * times;
}
}
object Plactice{
def main(args: Array[String]){
loopCall(10, nTimes(5))
}
def loopCall(n:Int, func:(Int) => Int) ={
for(i <- 1 to n)
print(func(i) + " ")
println
}
def nTimes(times : Int) : (Int) => Int = {
(value : Int) => value * times;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment