Created
September 9, 2012 15:30
-
-
Save daneko/3685072 to your computer and use it in GitHub Desktop.
Scalaの部分適応とカリー化
This file contains hidden or 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 hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment