Last active
November 5, 2017 13:33
-
-
Save deque-blog/49f6f58e70287d51f9fc175c4b6147ae to your computer and use it in GitHub Desktop.
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
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