I have a project whose main cabal component is a library
library
hs-source-dirs: src
...
and which also defines
executable todo
if !flag(example)
Buildable: False
ghc-options: -Wall
cpp-options: -DGHCJS_BROWSER
default-language: Haskell2010
hs-source-dirs: example/todo
other-modules: TodoDispatcher
TodoStore
TodoComponents
main-is: Main.hs
Now if I try to type check one file I get the following error
Configuring react-flux-1.0.3...
EXCEPTION: types:
Could not find module ‘TodoDispatcher’
Use -v to see a list of the files searched for.
And if I do so from the command line I get
$ ghc-mod --ghcOpt=-v7 type example/todo/TodoViews.hs 29 28 not sandboxed
EXCEPTION: types:
Could not find module ‘TodoDispatcher’
Locations searched:
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/TodoDispatcher.hs
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/TodoDispatcher.lhs
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/TodoDispatcher.hsig
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/TodoDispatcher.lhsig
src/TodoDispatcher.hs
src/TodoDispatcher.lhs
src/TodoDispatcher.hsig
src/TodoDispatcher.lhsig
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/autogen/TodoDispatcher.hs
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/autogen/TodoDispatcher.lhs
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/autogen/TodoDispatcher.hsig
.stack-work/dist/x86_64-osx/Cabal-1.22.8.0/build/autogen/TodoDispatcher.lhsig
So it seems to ignore the hs-source-dirs
setting of the component which the current file I try to typecheck belongs to, and instead consider the one from the first component of the package, just like cabal repl would do by default
By default cabal repl loads the first component in a package.
How can I change that nice bit of global state ?
OK so here's what you should do in order to get this to work:
You need to edit the cabal file and change the flag of the component to
`Buildable : True`
You can then type check
$ ghc-mod --ghcOpt=-v7 type example/todo/TodoViews.hs 29 28 not sandboxed
29 24 29 34 "[Char]"
27 25 33 12 "TextInputArgs"
27 9 33 12 "ReactElementM [
In Emacs:
You need to get out of Emacs maybe
You need to open your file and haskell-process-load-file
(aka C-c C-l, aka Space m s b)
It should have loaded the correct "target", which is haskell-mode parlance for "component" in cabal. If that works then ghc-mod should also. (?)
http://haskell.github.io/haskell-mode/manual/latest/Interactive-Haskell.html
14.8.1 Changing REPL target
With haskell-session-change-target you can change the target for REPL session.
After REPL session started, in haskell-interactive-mode buffer invoke the haskell-session-change-target and select from available targets for
- Testing
- Benchmark
- Executable
- Library
Answer “yes” to restart the session and run your tests, benchmarks, executables.