user1546806
user1546806

Reputation: 147

Language.Haskell.Interpreter - how to properly call IO actions?

Following the example file, I try to dynamically call an IO action.

testHint :: Interpreter ()
testHint = do
                setImportsQ [("Prelude", Nothing)]
                let somecode = "putStrLn \"some string\""
                interpret somecode (as :: IO ())
                say "hello"

Unfortunately, the string "some string" is never printed. I also tried to call writeFile but no file was created, either.

So what is needed to enable these side effects? Thank you!

Upvotes: 1

Views: 185

Answers (1)

hammar
hammar

Reputation: 139830

interpret won't run any IO actions on its own. It'll just evaluate it and return it to you and then you have to run it yourself, for example using liftIO:

interpret somecode (as :: IO ()) >>= liftIO

Upvotes: 3

Related Questions