Skip to content

Instantly share code, notes, and snippets.

@myuon
Created June 9, 2013 03:17
Show Gist options
  • Save myuon/5737483 to your computer and use it in GitHub Desktop.
Save myuon/5737483 to your computer and use it in GitHub Desktop.
{-# 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
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