making hint faster; pre-loading some modules at compiled time? Is there a straightforward way to do that? #167
-
looks like Is there an easy way to pre-load modules into the interpreter at compile time? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 7 replies
-
will the packages included in |
Beta Was this translation helpful? Give feedback.
-
or does GHC handle the "pre-loading" at compile time already? (So the one of the only downsides of interpreting (in hint vs having the code built into a module) is that I don't get use to use Template Haskell? Any sources where I can read more on it? Thanks! ) |
Beta Was this translation helpful? Give feedback.
-
First of all, since you're concerned about performance, I recommend reading the GHCi documentation on loading compiled code. GHCi and hint are both using the ghc library, a lot of the ghci documentation should apply to hint as well. |
Beta Was this translation helpful? Give feedback.
-
To clarify: with the above approach,
I don't think this is what you mean by "pre-loading". |
Beta Was this translation helpful? Give feedback.
-
Oh boy, good luck with that! I know that ghc can produce wasm code, but is it possible to compile ghc itself into wasm yet? it sounds much harder. hint uses the ghc library, which holds most of the code for the ghc executable. so if it's not possible to compile ghc itself into wasm, it's probably not possible to compile the ghc library into wasm either. In particular, can wasm code load files from the filesystem? The ghc library relies on a ton of files being installed on the target machine, many of which are installed on your machine when you install the ghc executable. Here is the full list of files I had to copy to a blank linux container in order to run a tiny hint program without installing ghc on that container. This includes some so... yeah, I would be very excited if I could run hint in the browser, but I think there's still a lot of work to be done until we can get there. |
Beta Was this translation helpful? Give feedback.
-
What do you mean? hint supports TemplateHaskell just fine: import Language.Haskell.Interpreter
-- |
-- >>> main
-- Right "Hello, world!"
main :: IO ()
main = do
r <- runInterpreter $ do
set [languageExtensions := [TemplateHaskell]]
setImports ["Prelude", "Language.Haskell.TH"]
interpret "$(litE (stringL \"Hello, world!\"))" (as :: String)
print r |
Beta Was this translation helpful? Give feedback.
-
Are you saying that you are writing import Language.Haskell.Interpreter
import Language.Haskell.Interpreter.Unsafe
-- |
-- >>> main
-- "hello"
-- Right ()
main :: IO ()
main = do
r <- unsafeRunInterpreterWithArgs ["-package acme-dont"] $ do
setImports ["Prelude", "Acme.Dont"]
ioAction1 <- interpret "do (putStrLn \"hello\")" (as :: IO ())
ioAction2 <- interpret "don't (putStrLn \"hello\")" (as :: IO ())
liftIO ioAction1 -- prints "hello"
liftIO ioAction2 -- doesn't
print r Note that the The only code which ghc runs at compile time is:
|
Beta Was this translation helpful? Give feedback.
-
Yes, there is! In the following program, 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 program, ghc loads the previously-compiled acme-dont package, finds the When you run the above program, the ghc library still reads a bunch of files, and loads the (compiled version of the) Prelude at runtime. And it interprets the program |
Beta Was this translation helpful? Give feedback.
Yes, there is! In the following program,
don't
is compiled into the executable, it is not loaded at runtime.When you compile the above…