3
votes

I have a library and I want my executable to be pretty much what I get when I cabal repl it, i.e. I want the user to be able to use Haskell expressions, and import the modules and use the data types that are defined in my library.

Is it possible? I get the idea that hint can only work with source files (which are not available to the user), but I'm not certain. When I tried to load modules from my library or from cabal packages that are globally installed, I got a vague error message saying that the module is a package module. In fact, almost whatever I write will do that too:

ghci> runInterpreter $ loadModules ["Not.A.Package.Module"]
Left (WontCompile [GhcError {errMsg = "<no location info>: error:\n    module \8216Not.A.Package.Module\8217 is a package module"}])

Is there any way to do this? (P.S. I'm using GHC 8.0.1 and plugins isn't supporting it, and I also got the idea it's a very dead project. If there's another way but hint & plugins I'm open to it).

1
Can ghci itself import these modules?n. 1.8e9-where's-my-share m.

1 Answers

0
votes

You could make yourself a stack project and put your code on which you depend on Hackage.

Then in your project add that package into your build-depends section of the *.cabal file. Then just import the stuff you need using setImportsQ from hint.

An example would be depending on Chart and Chart-diagrams:

build-depends:       base
                     ...
                     , Chart
                     , Chart-diagrams

And then in your evaluation function:

setImportsQ[ ("Prelude",Nothing)
           , ("Graphics.Rendering.Chart.Easy", Nothing)
           , ("Graphics.Rendering.Chart.Backend.Diagrams", Nothing)
           ]