30

cabal repl is quite useful for debugging a library, however ghci will have all packages hidden that aren't dependencies of the cabal package. While that is certainly a good thing for cabal build, for repl it means I can't load something from an unrelated package for a quick test.

I can access any package by issuing :set -package, but that'll unload all modules from the pacakge I'm working on, defeating the point of cabal repl.

What's a nice way to simply load packages I have installed, but don't want as dependencies to my library?

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319

4 Answers4

39
cabal repl --ghc-option='-package xyz'

This will load the package you are calling cabal repl from and the package xyz.

To do that after the fact, i.e. when you're already in the REPL and want to load an extra helper module from another package:

GHCi> :set -package xyz
GHCi> :m +XYZ.Module.You.Suddenly.Need
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
SvenK
  • 2,584
  • 2
  • 21
  • 24
  • 1
    Could you also specify a path to a local package, or a git url? – SwiftsNamesake Sep 16 '17 at 05:02
  • 1
    1) `cabal repl` (I actually used `cabal new-repl` in the hope it works similarly) tried rebuilding (and failed); 2) `:set -package` unloaded the modules from the current package, as the OP mentioned, and I don't see how to get them back :( – Nickolay May 02 '18 at 12:21
9

When I needed QuickCheck library in scope of ghci I tried

cabal repl --ghc-option='-package QuickCheck'

and it didn't work at all.

The following saved my day

cabal repl --build-depends "QuickCheck >= 2.14"
slavik
  • 1,223
  • 15
  • 17
2

One way (not optimal though) would be to modify your cabal file and add a manual/false flag extra_dependency, add the dependencies you need in a conditional build-depends section.

The problem indeed, is you need to manually edit the cabal file each you want to access an hidden library but at least, you library doesn't depend officially on those libraries.

Otherwise, you might be able to set the module path to look into your sandbox cache.

mb14
  • 22,276
  • 7
  • 60
  • 102
2

This is only tangential. I searched for how to do with stack repl. With Stack you do:

stack repl --package xyz

Here repl is synonymous with ghci.

sshine
  • 15,635
  • 1
  • 41
  • 66