Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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