Created
June 9, 2013 03:17
-
-
Save myuon/5737483 to your computer and use it in GitHub Desktop.
This file contains 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
{-# LANGUAGE GADTs #-} | |
import Control.Monad | |
import Control.Monad.Operational.Simple | |
data Simple a where | |
End :: Simple a | |
Put :: String -> Simple () | |
Get :: Int -> Simple String | |
put :: String -> Program Simple () | |
put = singleton . Put | |
end :: Program Simple a | |
end = singleton End | |
get :: Int -> Program Simple String | |
get = singleton . Get | |
run :: Program Simple a -> IO a | |
run = interpret step | |
where | |
step :: Simple x -> IO x | |
step (Put a) = putStrLn a | |
step End = putStrLn "End" >> undefined | |
step (Get n) = replicateM n getChar | |
quiz :: Program Simple String | |
quiz = do | |
put "Q.This program is written in _______.(7 letters)" | |
ch <- get 7 | |
put $ "Your answer:" ++ ch | |
if ch == "Haskell" | |
then put "Congratulations!" | |
else put "Wooooops!! You may have misspelled, haha." | |
end | |
main = run quiz |
This file contains 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
Q.This program is written in _______.(7 letters) | |
conglalalla | |
Your answer:conglal | |
Wooooops!! You may have misspelled, haha. | |
End | |
Operational.hs: Prelude.undefined | |
Q.This program is written in _______.(7 letters) | |
Haskell | |
Your answer:Haskell | |
Congratulations! | |
End | |
Operational.hs: Prelude.undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment