Skip to content

Instantly share code, notes, and snippets.

@shoheiyokoyama
Last active February 26, 2017 06:04
Show Gist options
  • Save shoheiyokoyama/e06efc028efe8b74257ba0b718eb7889 to your computer and use it in GitHub Desktop.
Save shoheiyokoyama/e06efc028efe8b74257ba0b718eb7889 to your computer and use it in GitHub Desktop.
Swiftエンジニアが学ぶ高階関数「カリー化関数」 ref: http://qiita.com/shoheiyokoyama/items/04416501389c69544c5a
Prelude> max 4 5
5
Prelude> (max 4) 5
5
multTree :: Int -> Int -> Int -> Int
multTree x y z = x * y * z
Prelude> multTree 3 5 9
135
Prelude> let multTwo = multTree 9
Prelude> :t multTwo
multiTwo :: Int -> Int -> Int
Prelude> let muitOne = multTwo 3
Prelude> :t muitOne
muitOne :: Int -> Int
func multiple(_ x: Int, _ y: Int) -> Int {
return x * y
}
multiple(3, 5)//15
func multiple(_ x: Int) -> (Int) -> Int {
return { y in x * y }
}
multiple(3)(5)//15
let multClosure = multiple(3)
multClosure(5)//15
multClosure(4)//12
Prelude> multTwo 3 2
162
Prelude> muitOne 5
135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment