Created
June 15, 2013 17:58
-
-
Save plaster/5788967 to your computer and use it in GitHub Desktop.
Eitherの練習。リスト脳。
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
| type FizzBuzz = Either Int String | |
| hit :: String -> FizzBuzz -> FizzBuzz | |
| hit s (Left _) = Right s | |
| hit s (Right s') = Right $ s ++ s' | |
| fizz :: [ FizzBuzz -> FizzBuzz ] | |
| fizz = cycle [ id, id, hit "fizz" ] | |
| buzz :: [ FizzBuzz -> FizzBuzz ] | |
| buzz = cycle [ id, id, id, id, hit "buzz" ] | |
| fizzbuzz :: [ FizzBuzz -> FizzBuzz ] | |
| fizzbuzz = zipWith (.) fizz buzz | |
| emit :: FizzBuzz -> String | |
| emit (Left n) = show n | |
| emit (Right s) = s | |
| fizzbuzzlist :: [String] | |
| fizzbuzzlist = map emit $ zipWith ($) fizzbuzz $ map Left [1..] | |
| main :: IO () | |
| main = mapM_ putStrLn $ take 100 fizzbuzzlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment