0
votes

Full reproducible project here: https://github.com/chrissound/215

I have the following simple cabal file which defines:

  • a library (source under src-lib)
  • executable (source under src) in the same project (which depends on the above local library)
cabal-version: 1.12
name:                HaskellNixCabalStarter
version:             0.1.0.0
author:              HaskellNixCabalStarter
maintainer:          HaskellNixCabalStarter
license:             MIT
build-type:          Simple

library
  exposed-modules:
      Hello
  other-modules:
      Paths_HaskellNixCabalStarter
  hs-source-dirs:
      src-lib
  build-depends:
      base >=4.12 && <4.13
  default-language: Haskell2010

executable app
  main-is: Main.hs
  other-modules:
      Paths_HaskellNixCabalStarter
  hs-source-dirs:
      src
  build-depends:
      HaskellNixCabalStarter
    , base >=4.12 && <4.13
  default-language: Haskell2010

I can open a GHCi repl with:

cabal v2-repl app

However, upon GHCi reloading (:r), it will only reload changes in the app executable, and disregard any changes in the library.

This seems like very limiting / incorrect behavior. How can I fix this / workaround this?

2
The reason for this is because your library compilation and dependenct tracking is done by cabal, outside of ghci.Ari Fordsham
Hmmm, does stack maybe not have this limitation?Chris Stryczynski

2 Answers

1
votes

There is a workaround, you either

  1. run cabal repl and then :load src/Main.hs, or
  2. with cabal repl app you'd need to :load src/Main.hs src-lib/Hello.hs.

Now :reload also reloads changes from dependencies.

In the first case it's the :load that somehow also starts loading/following the dependencies. (Not sure why cabal repl app isn't doing exactly the same.)

On the second case you need to explicitly name the modules you want to follow. Also, you need to have the module in who's namespace you want to be in, first. So :load src/Main.hs ..others...

See this on reddit. It appears that cabal can only have one "unit" loaded, but loading other sources with :load seems to subvert that.

0
votes

I don't think it can be done (yet?). Evidence:

jeff@jbb-dell:cabal-experim$ tree
.
├── cabal.project
├── P1
│   ├── app
│   │   ├── Lib.hs
│   │   └── Main.hs
│   └── P1.cabal
└── P2
    ├── P2.cabal
    └── src
        └── MyLib.hs

jeff@jbb-dell:cabal-experim$ cabal repl P1 P2
cabal: Cannot open a repl for multiple components at once. The targets 'P1'
and 'P2' refer to different components.

The reason for this limitation is that current versions of ghci do not support
loading multiple components as source. Load just one component and when you
make changes to a dependent component then quit and reload.