Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active October 30, 2017 09:01
Show Gist options
  • Save deque-blog/f9f42131ccc3ddfe14073c53341aee58 to your computer and use it in GitHub Desktop.
Save deque-blog/f9f42131ccc3ddfe14073c53341aee58 to your computer and use it in GitHub Desktop.
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