Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installed parsec in sandbox, but can't find libraries when trying to load file in ghci

Tags:

haskell

ghc

cabal

tl;dr: installed library with cabal sandbox, ghci still complains that the library is missing

I have a directory where I am developing some Haskell stuff. This used to work fine on another computer, with ghc 7.6, but now that I'm working on another computer with ghc 7.8.2 (I don't know if the version would matter) I get errors like this:

Prelude> :l Interpreter.hs

Parser.hs:9:8: Could not find module ‘Text.ParserCombinators.Parsec’ Perhaps you meant Text.ParserCombinators.ReadPrec (from base) Text.ParserCombinators.ReadP (from base) Use -v to see a list of the files searched for.

when trying to load files from ghci. These files are located in BASE/src/Lib, where BASE is the directory with LIB.cabal and all that. So I figured there was something up with cabal. Wanting to avoid the dreaded 'cabal hell', I made a sandbox in the project (cabal sandbox init), which I hadn't used before. I then manually removed the other cabal related stuff and did cabal init. I did cabal install --dependencies-only, but that didn't actually install anything (I'm guessing because of --dependencies-only? I was too paranoid of global installs to use regular cabal install). So I tried to add things manually to my .cabal file (is that how you should do this?), namely:

build-depends:

base >=4.7 && <4.8,

containers >=0.5 && <0.6,

-- 

parsec == 3.1.* -- THIS is the line I added

Now I did cabal install --dependencies-only. Lo and behold, things were actually installed, specifically:

[21 of 25] Compiling Text.Parsec ( Text/Parsec.hs, dist/dist-sandbox-a2fe5095/build /Text/Parsec.o )

...

In-place registering parsec-3.1.5... Installing library in /home/PATHTODIR/Stack Lang/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.2/parsec-3.1.5 Registering parsec-3.1.5... Installed parsec-3.1.5

So I tried to load the same file in ghci, yielding the same error. Note that the problem was Text.ParserCombinators.Parsec, which seemed to be installed just fine according to when I ran cabal install --dependencies-only. Here is the output that I get with ghc -v Interpreter.hs:

Glasgow Haskell Compiler, Version 7.8.2, stage 2 booted by GHC version 7.4.1

Using binary package database: /opt/ghc/7.8.2/lib/ghc-7.8.2/package.conf.d/package.cache

wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8

wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-dc47f6b546fc171f67a7f7d311684a99

wired-in package base mapped to base-4.7.0.0-018311399e3b6350d5be3a16b144df9b

wired-in package rts mapped to builtin_rts

wired-in package template-haskell mapped to template-haskell-2.9.0.0-

dcc8c210fb02937e104bc1784d7b0f06

wired-in package dph-seq not found.

wired-in package dph-par not found.

Hsc static flags:

wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8

wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-

dc47f6b546fc171f67a7f7d311684a99

wired-in package base mapped to base-4.7.0.0-018311399e3b6350d5be3a16b144df9b

wired-in package rts mapped to builtin_rts

wired-in package template-haskell mapped to template-haskell-2.9.0.0-

dcc8c210fb02937e104bc1784d7b0f06

wired-in package dph-seq not found.

wired-in package dph-par not found.

* Chasing dependencies:

Chasing modules from: *Interpreter.hs

Parser.hs:9:8: Could not find module ‘Text.ParserCombinators.Parsec’ Perhaps you meant Text.ParserCombinators.ReadPrec (from base) Text.ParserCombinators.ReadP (from base) Locations searched: Text/ParserCombinators/Parsec.hs Text/ParserCombinators/Parsec.lhs

Parser.hs:10:18: Could not find module ‘Text.Parsec.Token’ Locations searched: Text/Parsec/Token.hs Text/Parsec/Token.lhs

Interpreter.hs:11:8: Could not find module ‘Control.Monad.Error’ Perhaps you meant Control.Monad.Fix (from base) Control.Monad.ST (from base) Control.Monad.Zip (from base) Locations searched: Control/Monad/Error.hs Control/Monad/Error.lhs

Interpreter.hs:15:8: Could not find module ‘Text.ParserCombinators.Parsec.Error’ Locations searched: Text/ParserCombinators/Parsec/Error.hs Text/ParserCombinators/Parsec/Error.lhs * Deleting temp files: Deleting: * Deleting temp dirs: Deleting:

like image 285
Guildenstern Avatar asked Dec 20 '22 15:12

Guildenstern


1 Answers

ghc/ghci are not automatically aware of sandboxes. They only look at the global and user package databases by default.

Either use cabal repl to launch ghci, or follow the recipies from my article cabal sandbox tips. Both may require a recent (post-1.18) cabal.

like image 161
Roman Cheplyaka Avatar answered Apr 09 '23 17:04

Roman Cheplyaka