Skip to content

Instantly share code, notes, and snippets.

@blippy
Created December 4, 2015 19:47
Show Gist options
  • Save blippy/dfccf68fd3482df57b98 to your computer and use it in GitHub Desktop.
Save blippy/dfccf68fd3482df57b98 to your computer and use it in GitHub Desktop.
Haskell interpreter: using "return"
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