Using GHCi to load a module without access to its source code
I create a simple module, TestModule.hs
, which contains a single exported top-level definition testval = 2
. I compile it, creating TestModule.o
and TestModule.hi
. I delete TestModule.hs
. I the开发者_如何学编程n load TestModule.o
in ghci
, like this:
~ λ ghci TestModule.o
GHCi, version 7.0.3.20110517: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Loading object (static) TestModule.o ... done
final link ... done
Prelude>
As you can see, TestModule
isn't in scope and I cannot access testval
. Why? How can I accomplish this without access to the source file?
Additional question: how do I accomplish the same thing using the hint
package?
Thanks!
You can't interpret something that's already been compiled. If you want to interpret it, you need the source. You can make a package, if you like. Instructions are here.
精彩评论