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
// 全部問題ない | |
def hoge(x:Int, y:Int, f:(Int, Int) => Int) = f(x,y) | |
// hogeをカリー化 | |
val fuga = hoge _ curried | |
// hogeを部分適応 | |
val piyo = hoge(3, _:Int, _:(Int, Int) => Int) | |
// 更に部分適応 | |
val moo = piyo(2, _:(Int, Int) => Int) | |
def mew(x:Int)(y:Int)(f:(Int, Int) => Int) = f(x,y) | |
// mewを部分適応 | |
val bow = mew(3)_ |
上記は問題ない。
全く問題ない。
問題は下
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
/** | |
* fugaもpiyoもすでに「関数オブジェクト」となっているので | |
* メソッド _ で関数オブジェクト化してはならない、というか出来ない | |
**/ | |
// fugaを部分適応 | |
// NG | |
//val fugafuga = fuga(3)_ | |
// OK | |
val fugafuga = fuga(3) | |
// piyoをカリー化 | |
// NG | |
//val piyopiyo = piyo _ curried | |
// OK | |
val piyopiyo = piyo curried |
一旦部分適応やらで作成したメソッドを再度カリー化したり
一旦カリー化されたメソッドを更に部分適応したりするときは _ が不要
というかつけると怒られる
とりあえずはそういうものって覚えればいい?
環境は
Scala2.9.2
MacOSX10.7
2012/09/12 追記
defで宣言した関数名の後ろに「_」をつけると、「関数オブジェクト」になる
なので、一回関数オブジェクトに変わっている → 次は変える必要はない(というか既に変換済み)
ということでいいんでしょうか?
2012/09/13 追記
http://togetter.com/li/154007
このあたりかな?