Created
June 22, 2012 16:39
-
-
Save numa08/2973904 to your computer and use it in GitHub Desktop.
C#とScalaで関数型言語プログラミング ref: http://qiita.com/items/0ffb676dcf0afff5d78b
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
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; | |
} | |
} |
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
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