Created
September 24, 2015 16:50
-
-
Save Sankame/d7a5a4c62240e6ef149d to your computer and use it in GitHub Desktop.
カリー化サンプル
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
●リスト1――カリー化する前の例 | |
object myapp { | |
def main(args: Array[String]) = { | |
println("100から200までの合計:" + total(100, 200)) | |
} | |
def total(min: Int, max: Int) = { | |
var res:Int = 0 | |
for(n:Int <- Range(min,max + 1)) | |
res += n | |
res | |
} | |
} | |
●リスト2――カリー化した例 | |
object myapp { | |
def main(args: Array[String]) = { | |
val curryobj = curryTotal(100) | |
println("100から200までの合計:" + curryobj(200)) | |
println("100から500までの合計:" + curryobj(500)) | |
println("100から1000までの合計:" + curryobj(1000)) | |
} | |
def curryTotal(min: Int) = (max: Int) => { | |
var res:Int = 0 | |
for(n:Int <- Range(min,max + 1)) | |
res += n | |
res | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment