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