Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- import Control.Monad.State
- data FizzNum = JustNum Int | Fizz | Buzz | FizzBuzz deriving (Read)
- instance (Show FizzNum) where
- show Fizz = "Fizz"
- show Buzz = "Buzz"
- show FizzBuzz = "Fizz Buzz"
- show (JustNum x) = show x
- toFizz x =
- if x `mod` 15 == 0 then FizzBuzz else
- if x `mod` 3 == 0 then Fizz else
- if x `mod` 5 == 0 then Buzz else JustNum x
- fizzBuzz = map toFizz [1..]
- mainLoop :: StateT [FizzNum] IO ()
- mainLoop = loop
- where
- loop = do
- (x:y:xs) <- get
- lift $ print x
- put xs
- s <- lift getLine
- if (s == show y) then loop else lift $ putStrLn "You lose!"
- main = runStateT mainLoop fizzBuzz
Advertisement
Add Comment
Please, Sign In to add comment