Guest User

Untitled

a guest
Apr 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. import System.Environment
  2. import qualified Data.Bifunctor as BF (first)
  3. import Text.Read (readEither)
  4.  
  5. numberOfRings :: [String] -> Either String Int
  6. numberOfRings [] = Left "You didn't give me the number of rings!"
  7. numberOfRings [n] = BF.first intError $ readEither n
  8. where intError _ = "That's not a valid integer..."
  9. numberOfRings _ = Left "What's all this?"
  10.  
  11. moves :: Either String Int -> String
  12. moves (Left s) = s
  13. moves (Right n) = "Woo!"
  14.  
  15. main = do
  16. args <- getArgs
  17. putStrLn . moves $ numberOfRings args
Add Comment
Please, Sign In to add comment