Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active October 30, 2017 09:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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