Skip to content

making hint faster; pre-loading some modules at compiled time? Is there a straightforward way to do that? #167

Answered by gelisam
archywillhe asked this question in Q&A
Discussion options

You must be logged in to vote

Is there an easy way to pre-load modules into the interpreter at compile time?

Yes, there is! In the following program, don't is compiled into the executable, it is not loaded at runtime.

import Acme.Dont
import Language.Haskell.Interpreter

type Don't = IO () -> IO ()

-- |
-- >>> main
-- "hello"
-- Right ()
main :: IO ()
main = do
  r <- runInterpreter $ do
    setImports ["Prelude"]
    ioAction1 <- interpret "do (putStrLn \"hello\")" (as :: IO ())
    mkIoAction2 <- interpret "\\don't -> don't (putStrLn \"hello\")" (as :: Don't -> IO ())
    let ioAction2 = mkIoAction2 don't
    liftIO ioAction1  -- prints "hello"
    liftIO ioAction2  -- doesn't
  print r

When you compile the above…

Replies: 8 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@archywillhe
Comment options

Comment options

You must be logged in to vote
1 reply
@archywillhe
Comment options

Comment options

You must be logged in to vote
2 replies
@archywillhe
Comment options

@archywillhe
Comment options

Comment options

You must be logged in to vote
2 replies
@archywillhe
Comment options

@archywillhe
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@archywillhe
Comment options

Answer selected by archywillhe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #166 on August 05, 2023 19:54.