Skip to content

Instantly share code, notes, and snippets.

@daneko
Created September 9, 2012 15:30
Show Gist options
  • Select an option

  • Save daneko/3685072 to your computer and use it in GitHub Desktop.

Select an option

Save daneko/3685072 to your computer and use it in GitHub Desktop.
Scalaの部分適応とカリー化
// 全部問題ない
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)_
/**
* 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