Can't load a module in GHCi

#1

I have an executable that uses a bunch of other packages I’ve written. It builds and passes all of my tests just fine.

nix-shell
cabal configure --enable-tests
cabal build --ghc-options=-Werror && cabal test && cabal install
…all works just fine

But I need to investigate a problem using GHCi. When I try to load the module of interest, I get a weird message about mismatched types… but the two definitions it points to are the same definition!

amy@wombat9000:~/néal/exp-dvector-prediction-wains (nix-shell) $ ghci
GHCi, version 8.4.4: http://www.haskell.org/ghc/  :? for help
package flags have changed, resetting and loading new packages...
package flags have changed, resetting and loading new packages...
package flags have changed, resetting and loading new packages...
package flags have changed, resetting and loading new packages...
cannot satisfy -package test-framework-hunit
    (use -v for more information)
cannot satisfy -package HUnit
    (use -v for more information)
cannot satisfy -package criterion
    (use -v for more information)
Loaded GHCi configuration from /home/amy/dotWombat/.ghci
λ> :l ALife.Creatur.Wain.DVector.Prediction.Experiment
[1 of 8] Compiling ALife.Creatur.Wain.DVector.Prediction.ActionInternal ( src/ALife/Creatur/Wain/DVector/Prediction/ActionInternal.hs, interpreted )

src/ALife/Creatur/Wain/DVector/Prediction/ActionInternal.hs:77:25: error:
    • Couldn't match expected type ‘creatur-wains-9.6:ALife.Creatur.Wain.UnitInterval.UIDouble’
                  with actual type ‘UIDouble’
      NB: ‘UIDouble’
            is defined in ‘ALife.Creatur.Wain.UnitInterval’
                in package ‘creatur-wains-9.6’
          ‘creatur-wains-9.6:ALife.Creatur.Wain.UnitInterval.UIDouble’
            is defined in ‘ALife.Creatur.Wain.UnitInterval’
                in package ‘creatur-wains-9.6’
    • In the second argument of ‘makeSimilar’, namely ‘r’
      In the second argument of ‘($)’, namely ‘makeSimilar x r y’
      In the expression: Add $ makeSimilar x r y
   |
77 |   = Add $ makeSimilar x r y
   |                         ^
Failed, no modules loaded.
λ

I can’t tell if this is a bug in GHCi, or if I’m invoking it in a way that NixOS doesn’t like. I would appreciate any suggestions on how to investigate why this is happening.

λ> :show language
base language is: Haskell2010
with the following modifiers:
  -XNoDatatypeContexts
  -XNondecreasingIndentation
  -XUnicodeSyntax
λ> :show packages
active package flags:
  -package random
  -package test-framework
  -package test-framework-quickcheck2
  -package QuickCheck
λ> :show imports
import Data.List
import Data.Maybe
import Test.QuickCheck
import Test.Framework ( defaultMain )
import Prelude -- implicit
0 Likes

#2

Did you try cabal repl? That’s the usual way to lauch ghci from a cabal project.

What is the output of ghc-pkg list?

1 Like

#3

Thank you, I’d forgotten about good old ghc-pkg; hadn’t used it in years. Now I see I have dozens of broken packages. Unregistering them all would take a while; I’d like to just clear it out and start fresh. In pre-NixOS days I would have done rm -rf ~/.cabal. How do I do this in NixOS?

0 Likes

#4

Cabal still works the same way. When you enter a nix-shell it just registers packages with ghc in a separate package database. The two should be orthogonal.

0 Likes