Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active November 5, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/49f6f58e70287d51f9fc175c4b6147ae to your computer and use it in GitHub Desktop.
Save deque-blog/49f6f58e70287d51f9fc175c4b6147ae to your computer and use it in GitHub Desktop.
password : Nat -> (String -> Bool) -> IOSpec Bool
password maxAttempt valid = recur (S Z) where
recur n = do
prnLine "Password:" -- `prnLine` instead of `putStrLn`
attempt <- readLine -- `readLine` instead of `getLine`
if valid attempt
then do
prnLine ("Successful login after " ++ show n ++ " attempt(s).")
pure True
else do
prnLine ("Login failed: " ++ show n ++ " attempt(s).")
if n < maxAttempt
then recur (n + 1)
else pure False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment