Last active
February 26, 2017 06:04
-
-
Save shoheiyokoyama/e06efc028efe8b74257ba0b718eb7889 to your computer and use it in GitHub Desktop.
Swiftエンジニアが学ぶ高階関数「カリー化関数」 ref: http://qiita.com/shoheiyokoyama/items/04416501389c69544c5a
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
Prelude> max 4 5 | |
5 | |
Prelude> (max 4) 5 | |
5 |
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
multTree :: Int -> Int -> Int -> Int | |
multTree x y z = x * y * z |
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
Prelude> multTree 3 5 9 | |
135 |
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
Prelude> let multTwo = multTree 9 | |
Prelude> :t multTwo | |
multiTwo :: Int -> Int -> Int | |
Prelude> let muitOne = multTwo 3 | |
Prelude> :t muitOne | |
muitOne :: Int -> Int |
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
func multiple(_ x: Int, _ y: Int) -> Int { | |
return x * y | |
} | |
multiple(3, 5)//15 |
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
func multiple(_ x: Int) -> (Int) -> Int { | |
return { y in x * y } | |
} | |
multiple(3)(5)//15 |
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
let multClosure = multiple(3) | |
multClosure(5)//15 | |
multClosure(4)//12 |
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
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