Inside the project, can I compile the module and interactively load the compiled module into ghci?
Typically, in a Haskell project, I either interact with ghci or compile the whole project using the cabal assembly.
However, in some cases I may have a computationally intensive procedure as well as some higher level scripting functions, for example, to select inputs for an analysis algorithm.
Is it possible to use GHCi + GHC so that I compile a computationally intensive module by loading the compiled code to run again with different inputs from GHCi?
source to share
Yes, you can load compiled modules into ghci; if there is a file named .hi
and .o
appropriately ghci will use them instead of interpreting the code in the corresponding file .hs
. After that, you will only have access to the operations that are exported from this module.
If you find yourself using a compiled loaded module when you want to interpret it, you can :load *foo.hs
tell ghci to ignore the compiled version and interpret foo.hs
.
source to share