Created
March 15, 2012 11:30
-
-
Save rirakkumya/2043771 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
この問題を解決するには、 | |
scala> val f:Int => Int = x => x | |
f: (Int) => Int = <function1> | |
この関数に数値を代入して、同じ関数を返す事が出来ないとダメなので解決出来ない。 | |
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
scala> def a(x:String=>Int)(y:(String=>Int) => String) = y(x) | |
a: (x: (String) => Int)(y: ((String) => Int) => String)String | |
これはOK | |
scala> val w = 3 | |
scala> a{x => x.toInt * w}{x => x("33") + "scala"} | |
res17: String = 99scala | |
で、もう一個関数増やして、 | |
def b(x:String=>Int)(y:(String=>Int) => String)(z:((String=>Int)=>String)=>Int) = | |
xをyに代入してyを評価させないで、zに代入したい。 | |
yを遅延評価させればいいんだろうけど、どう書けばいいんだろう。 | |
def c(x:String=>Int)(y:(String=>Int) => String)(z:((String=>Int)=>String)=>Int) = y(x) //これはOK | |
def d(x:String=>Int)(y:(String=>Int) => String)(z:((String=>Int)=>String)=>Int) = z(y) //これもOK | |
== sample == | |
def e(x:String=>Int)(y:(String=>Int) => String)(z:((String=>Int),((String=>Int)=>String))=>Int) = z(x,y) | |
使い方は
scala> e{s => s.toInt * 3}{f => f("100").toString + "1"}{(x) => (y) => x("100")
- y(s => s.toInt).toInt}
res4: Int = 1301
な感じで。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scala> def e(x:String=>Int)(y:(String=>Int) => String)(z: (String=>Int) => ((Str
ing => Int) => String) => Int) = z(x)(y)
e: (x: String => Int)(y: String => Int => String)(z: String => Int => String =>
Int => String => Int)Int
であってます?