Skip to content

Instantly share code, notes, and snippets.

@Ap0c
Created April 15, 2018 22:06
Show Gist options
  • Save Ap0c/01e1c435345b5572f50dc67a8ddf94fb to your computer and use it in GitHub Desktop.
Save Ap0c/01e1c435345b5572f50dc67a8ddf94fb to your computer and use it in GitHub Desktop.
The start of a solution to the tower of hanoi.
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