Using cabal repl
seems to do nothing at all when used on library projects, but works fine for executable projects. Is this expected behavior that I just don't understand?
If I have a file containing simply
go = putStrLn "test"
and use cabal init
with all the defaults (but choose "library" as the type), then running cabal repl
just produces the some text about configuring and preprocessing the library and never enters a REPL environment. The exact same steps, but with "executable" selected as the type, puts me right into GHCi as expected.
The code works fine when loaded directly into GHCi.
If the project contains multiple remote package repositories it will update the index of all of them (e.g. when using overlays). cabal v2-build takes a set of targets and builds them. It automatically handles building and installing any dependencies of these targets. A target can take any of the following forms:
Fortunately, starting with Cabal 1.8.0.4, executables can also declare the package that they are in as a dependency, and Cabal will treat them as if they were in another package that depended on the library.
The library section may also contain build information fields (see the section on build information ). Cabal 2.0 and later support “internal libraries”, which are extra named libraries (as opposed to the usual unnamed library section).
Starting with Cabal 2.0, private internal sub-library components can be defined by setting the name field to a name different from the current package’s name; see section on Internal Libraries for more information. The library section should contain the following fields: A list of modules added by this package.
For cabal repl
to load your modules, you have to first name them in code and then specify them in your project's .cabal
file as exposed:
-- MyModule.hs
module MyModule where
go = putStrLn "test"
-- MyProject.cabal
name: MyProject
-- other info ...
library
exposed-modules: MyModule
-- other options ...
Then when you run cabal repl
, it'll have access to everything in your sandbox (if present) and the exposed modules. It might also work if you specify them as other-modules
instead of exposed-modules
, but I haven't tried that one out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With