Skip to content

Instantly share code, notes, and snippets.

@deque-blog

deque-blog/echo_bad_2.idr

Last active Oct 30, 2017
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