Guest User

Untitled

a guest
Dec 12th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Monad
  2. import Control.Monad.State
  3.  
  4. data FizzNum = JustNum Int | Fizz | Buzz | FizzBuzz deriving (Read)
  5.  
  6. instance (Show FizzNum) where
  7.   show Fizz = "Fizz"
  8.   show Buzz = "Buzz"
  9.   show FizzBuzz = "Fizz Buzz"
  10.   show (JustNum x) = show x
  11.  
  12. toFizz x =
  13.   if x `mod` 15  == 0 then FizzBuzz else
  14.     if x `mod` 3 == 0 then Fizz else
  15.       if x `mod` 5 == 0 then Buzz else JustNum x
  16.  
  17. fizzBuzz = map toFizz [1..]
  18.  
  19. mainLoop :: StateT [FizzNum] IO ()
  20. mainLoop = loop
  21.     where
  22.       loop = do
  23.         (x:y:xs) <- get
  24.         lift $ print x
  25.         put xs
  26.         s <- lift getLine
  27.         if (s == show y) then loop else lift $ putStrLn "You lose!"
  28.  
  29. main = runStateT mainLoop fizzBuzz
Advertisement
Add Comment
Please, Sign In to add comment