Created
April 15, 2018 22:06
-
-
Save Ap0c/01e1c435345b5572f50dc67a8ddf94fb to your computer and use it in GitHub Desktop.
The start of a solution to the tower of hanoi.
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment