Created
December 4, 2015 19:47
-
-
Save blippy/dfccf68fd3482df57b98 to your computer and use it in GitHub Desktop.
Haskell interpreter: using "return"
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
import Control.Monad | |
import Data.List | |
import Language.Haskell.Interpreter | |
main :: IO () | |
main = do r <- runInterpreter testHint | |
case r of | |
Left err -> printInterpreterError err | |
Right () -> putStrLn "that's all folks" | |
-- observe that Interpreter () is an alias for InterpreterT IO () | |
testHint :: Interpreter () | |
testHint = do | |
setImportsQ [("Prelude", Nothing), ("Data.Map", Just "M"), ("Language.Haskell.Interpreter", Nothing)] | |
res <- interpret "return $ show $ 10+2" (as:: InterpreterT IO String) | |
res1 <- res | |
say res1 | |
say "Bye" | |
say :: String -> Interpreter () | |
say = liftIO . putStrLn | |
printInterpreterError :: InterpreterError -> IO () | |
printInterpreterError e = putStrLn $ "Ups... " ++ (show e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment