Last active
July 6, 2017 15:59
-
-
Save jmikkola/64c215a532668c69ef510dbac00d285b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| data IOOp | |
| = EndProgram | |
| | ReadLine (String -> IOOp) | |
| | WriteLine String IOOp | |
| runOp :: IOOp -> IO () | |
| runOp EndProgram = return () | |
| runOp (ReadLine f) = do | |
| line <- getLine | |
| let nextOp = f line | |
| runOp nextOp | |
| runOp (WriteLine line nextOp) = do | |
| putStrLn line | |
| runOp nextOp | |
| main :: IO () | |
| main = | |
| if checkProgram testProgram | |
| then do | |
| putStrLn "test passed" | |
| runOp testProgram | |
| else putStrLn "test failed" | |
| testProgram :: IOOp | |
| testProgram = | |
| WriteLine | |
| "enter a line>" | |
| $ ReadLine (\l -> | |
| WriteLine l $ | |
| WriteLine l $ | |
| EndProgram) | |
| checkProgram :: IOOp -> Bool | |
| checkProgram p = case p of | |
| (WriteLine "enter a line>" x) -> case x of | |
| (ReadLine f) -> case f "test string" of | |
| (WriteLine "test string" y) -> case y of | |
| (WriteLine "test string" EndProgram) -> True | |
| _ -> False | |
| _ -> False | |
| _ -> False | |
| _ -> False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment