Last active
October 30, 2017 09:01
-
-
Save deque-blog/f9f42131ccc3ddfe14073c53341aee58 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
echo : IO () | |
echo = loop (const True) where | |
loop : (String -> Bool) -> IO () | |
loop isDifferent = do -- `isDifferent` refers to the previous string | |
putStr "in> " | |
l <- getLine | |
when (l /= "quit") $ do | |
when (isDifferent l) $ -- If the string is different from the previous | |
putStrLn ("out> " ++ l) -- Echo the string in standard output | |
loop (/= l) -- Track the last read string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment