Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Environment
- import qualified Data.Bifunctor as BF (first)
- import Text.Read (readEither)
- numberOfRings :: [String] -> Either String Int
- numberOfRings [] = Left "You didn't give me the number of rings!"
- numberOfRings [n] = BF.first intError $ readEither n
- where intError _ = "That's not a valid integer..."
- numberOfRings _ = Left "What's all this?"
- moves :: Either String Int -> String
- moves (Left s) = s
- moves (Right n) = "Woo!"
- main = do
- args <- getArgs
- putStrLn . moves $ numberOfRings args
Add Comment
Please, Sign In to add comment