Created
February 4, 2015 12:51
-
-
Save shigemk2/e0d03ea134ce034c0663 to your computer and use it in GitHub Desktop.
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
-- 関数はカリー化されているので、 この両側の xs は省略できます | |
sum' :: (Num a) => [a] -> a | |
sum' xs = foldl (+) 0 xs | |
-- 省略したのがこれ。 | |
sum'' :: (Num a) => [a] -> a | |
sum'' = foldl (+) 0 | |
oddSquareSum :: Integer | |
oddSquareSum = sum (takeWhile (<10000) (filter odd (map (^2) [1..]))) | |
-- 関数合成の応用 | |
oddSquareSum' :: Integer | |
oddSquareSum' = sum . takeWhile (<10000) . filter odd $ map (^2) [1..] | |
main = do | |
print $ sum' [1,2,3,4,5] | |
print $ sum'' [1,2,3,4,5] | |
print $ oddSquareSum | |
print $ oddSquareSum' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment