Skip to content

Instantly share code, notes, and snippets.

@jmikkola
Last active July 6, 2017 15:59
Show Gist options
  • Select an option

  • Save jmikkola/64c215a532668c69ef510dbac00d285b to your computer and use it in GitHub Desktop.

Select an option

Save jmikkola/64c215a532668c69ef510dbac00d285b to your computer and use it in GitHub Desktop.
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