ghc error: hidden package, but it's actually exposed - haskell

I'm trying to use the package Parsec.
When I run ghc Main.hs I get the error message:
Could not load module ‘Text.Parsec’
It is a member of the hidden package ‘parsec-3.1.14.0’.
You can run ‘:set -package parsec’ to expose it.
However, the package is supposed to be exposed already: ghc-pkg list gives
usr/lib/ghc/package.conf.d
Agda-2.6.0.1
Cabal-2.4.0.1
...
parsec-3.1.13.0
...
What should I do get ghc load it automatically?
The full error message mentioned both versions of the package:
ExpScanner.hs:13:1: error:
Could not load module ‘Text.Parsec’
It is a member of the hidden package ‘parsec-3.1.14.0’.
You can run ‘:set -package parsec’ to expose it.
(Note: this unloads all the modules in the current scope.)
It is a member of the hidden package ‘parsec-3.1.13.0’.
You can run ‘:set -package parsec’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v to see a list of the files searched for.
ExpScanner.hs is a moduled called by Main.
The full output of ghc-pkg list is
/usr/lib/ghc/package.conf.d
Agda-2.6.0.1
Cabal-2.4.0.1
EdisonAPI-1.3.1
EdisonCore-1.3.2.1
GLURaw-2.0.0.4
GLUT-2.7.0.15
HTTP-4000.3.14
HUnit-1.6.0.0
ObjectName-1.1.0.1
OpenGL-3.0.3.0
OpenGLRaw-3.3.3.0
QuickCheck-2.12.6.1
STMonadTrans-0.4.3
StateVar-1.1.1.1
aeson-1.4.2.0
array-0.5.3.0
async-2.2.2
attoparsec-0.13.2.2
base-4.12.0.0
base-compat-0.10.5
binary-0.8.6.0
blaze-builder-0.4.1.0
blaze-html-0.9.1.1
blaze-markup-0.8.2.2
boxes-0.1.5
bytestring-0.10.8.2
call-stack-0.1.0
case-insensitive-1.2.0.11
containers-0.6.0.1
data-hash-0.2.0.1
deepseq-1.4.4.0
directory-1.3.3.0
dlist-0.8.0.6
edit-distance-0.2.2.1
equivalence-0.3.4
erf-2.0.0.0
exceptions-0.10.2
fgl-5.7.0.1
filepath-1.4.2.1
fixed-0.2.1.1
geniplate-mirror-0.7.6
ghc-8.6.5
ghc-boot-8.6.5
ghc-boot-th-8.6.5
ghc-compact-0.1.0.0
ghc-heap-8.6.5
ghc-prim-0.5.3
ghci-8.6.5
gitrev-1.3.1
half-0.3
hashable-1.2.7.0
hashtables-1.2.3.3
haskeline-0.7.4.3
haskell-src-1.0.3.0
hpc-0.6.0.3
html-1.0.1.2
ieee754-0.8.0
integer-gmp-1.0.2.0
integer-logarithms-1.0.3
libiserv-8.6.3
mtl-2.2.2
murmur-hash-0.1.0.9
network-2.8.0.1
network-uri-2.6.1.0
parallel-3.2.2.0
parsec-3.1.13.0
pretty-1.1.3.6
primitive-0.6.4.0
process-1.6.5.0
random-1.1
regex-base-0.93.2
regex-compat-0.95.1
regex-posix-0.95.2
regex-tdfa-1.2.3.2
rts-1.0
scientific-0.3.6.2
split-0.2.3.3
stm-2.5.0.0
strict-0.3.2
syb-0.7.1
tagged-0.8.6
template-haskell-2.14.0.0
terminfo-0.4.1.2
text-1.2.3.1
tf-random-0.5
th-abstraction-0.2.11.0
time-1.8.0.2
time-locale-compat-0.1.1.5
transformers-0.5.6.2
transformers-compat-0.6.5
unix-2.7.2.2
unordered-containers-0.2.10.0
uri-encode-1.5.0.5
utf8-string-1.0.1.1
uuid-types-1.0.3
vector-0.12.0.3
xhtml-3000.2.2.1
zlib-0.6.2
/home/venanzio/.ghc/x86_64-linux-8.6.5/package.conf.d
Cabal-3.2.0.0
base16-bytestring-0.1.1.6
base64-bytestring-1.0.0.3
conway-0.1.0.0
cryptohash-sha256-0.11.101.0
echo-0.1.3
ed25519-0.0.5.0
hackage-security-0.6.0.1
lukko-0.1.1.2
resolv-0.1.2.0
tar-0.5.1.1

This looks like an issue with global vs local installs. Oh, and there it is in your ghc-pkg list output. You've got a multiuser ghc install and a single-user list of packages you've installed. Things work when you run ghc as a superuser because they won't see your local (per-user) installs.
This is going to cause problems unless you use a tool to manage your environment for you. Both cabal and stack can handle this fine. I prefer cabal because it doesn't need coaxing to work with your preinstalled GHC, but this is a matter that has caused religious wars in the past. I won't argue against stack if you have a good resource for using it instead.

Related

Acid-State example compiled error. No No instance for (Control.Monad.Reader.Class.MonadReader FailureDb (Query FailureDb))

I was trying acid example but compile error.
The error message says no instance No instance for MonadState, No instance for MonadReader.
This article says it is due to two different mtl versions installed.
And I am using nix-shell in nixos:
ghc-pkg list | grep acid
acid-state-0.14.3
ghc-pkg list | grep mtl
mtl-2.2.1
mtl-2.2.2
However, if I don't use acid-state package when I enter nix-shell, I got:
ghc-pkg list | grep mtl
mtl-2.2.2
That probably means acid-state is using different mtl version than Control.Monad.Reader.
But acid-state's stack.yaml in github is lts-11.15, which has mtl-2.2.2.
So what should I do to make it work?
Stack and Cabal-install have similar problems when dealing with GHC's package dbs, but these problems can be avoided:
Stack
When I use Stack, I don't run it in a nix-shell, so that the nix-shell can't add packages to the wrapped GHC command that Stack will then consider to be system packages ('global' in Cabal terminology). I am not sure whether this is the only valid approach though.
Cabal-install only
When calling Cabal in a nix-shell, you should add these flags to prevent GHC from looking at the wrong package db: cabal configure --package-db=clear --package-db=global. The GHC wrapper will make the Nix-managed dependencies appear in the 'global' package db.

Haskell Stack failing to install easyrender

I have GHC 8.0.2 installed on a Haskell stack, and I need a certain number of packages on it for my project, one being easyrender.
I install it using the following command, which works for all other package installations:
stack install easyrender
I get the following output:
easyrender-0.1.1.2: configure
-- While building package easyrender-0.1.1.2 using:
/home/nathan/.stack/programs/x86_64-linux/ghc-8.0.2/bin/ghc --make -odir /tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup -hidir /tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup -i -i. -clear-package-db -global-package-db -package-db=/home/nathan/.stack/snapshots/x86_64-linux/ghc-8.0.2/8.0.2/pkgdb -package-db=/home/nathan/.stack/global-project/.stack-work/install/x86_64-linux/ghc-8.0.2/8.0.2/pkgdb -hide-all-packages -package-id=base-4.9.1.0 -package-id=superdoc-0.1.2.5-9gGVGYAJpHrGct376cUN41 -optP-include -optP/tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup/setup_macros.h /tmp/stack5987/easyrender-0.1.1.2/Setup.hs /home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -main-is StackSetupShim.mainOverride -o /tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup/setup -threaded
Process exited with code: ExitFailure 1
Logs have been written to: /home/nathan/.stack/global-project/.stack-work/logs/easyrender-0.1.1.2.log
[1 of 2] Compiling Main ( /tmp/stack5987/easyrender-0.1.1.2/Setup.hs, /tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack5987/easyrender-0.1.1.2/.stack-work/dist/x86_64-linux/Cabal-1.24.2.0/setup/StackSetupShim.o )
/home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs:3:1: error:
Failed to load interface for ‘Distribution.PackageDescription’
It is a member of the hidden package ‘Cabal-2.0.1.0’.
It is a member of the hidden package ‘Cabal-1.24.2.0’.
Use -v to see a list of the files searched for.
/home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs:4:1: error:
Failed to load interface for ‘Distribution.Simple’
It is a member of the hidden package ‘Cabal-2.0.1.0’.
It is a member of the hidden package ‘Cabal-1.24.2.0’.
Use -v to see a list of the files searched for.
/home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs:5:1: error:
Failed to load interface for ‘Distribution.Simple.Build’
It is a member of the hidden package ‘Cabal-2.0.1.0’.
It is a member of the hidden package ‘Cabal-1.24.2.0’.
Use -v to see a list of the files searched for.
/home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs:6:1: error:
Failed to load interface for ‘Distribution.Simple.Setup’
It is a member of the hidden package ‘Cabal-2.0.1.0’.
It is a member of the hidden package ‘Cabal-1.24.2.0’.
Use -v to see a list of the files searched for.
/home/nathan/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs:7:1: error:
Failed to load interface for ‘Distribution.Simple.LocalBuildInfo’
It is a member of the hidden package ‘Cabal-2.0.1.0’.
It is a member of the hidden package ‘Cabal-1.24.2.0’.
Use -v to see a list of the files searched for.
Since Cabal seems to be a problem, I tried running stack install Cabal, but that doesn't do anything. The log file referenced just says the same thing as the output.
Ideas?
Nathan
This is a bug in the easyrender package description. Note that cabal-install's "new-build" encounters the same problem. See my comment on this stack issue: https://github.com/commercialhaskell/stack/issues/3560#issuecomment-344075524
Workaround is as described by Thomas's answer, and also in the issue at https://github.com/commercialhaskell/stack/issues/3560#issuecomment-343980627
The next stack release will emit a warning about this circumstance, which should reduce confusion in the future.
Unfortunately, easyrender does not have an issue tracker, it appears to only have a hackage page. I have emailed the author requesting that he fix this.
No such problems with cabal-install:
% cabal install easyrender
Resolving dependencies...
Downloading superdoc-0.1.2.5...
Configuring superdoc-0.1.2.5...
Building superdoc-0.1.2.5...
Installed superdoc-0.1.2.5
Downloading easyrender-0.1.1.2...
Configuring easyrender-0.1.1.2...
Building easyrender-0.1.1.2...
Installed easyrender-0.1.1.2
So I'm guessing this is an issue with stack handling non-simple builds in a different manner. Namely, cabal-install seems to assume Cabal is a dependency of the setup.hs while stack does not.
Just to check, I tried and could produce your same issue but adding Cabal to the setup-depends: line of the easyrender.cabal made it work fine.

At least the following dependencies are missing

I am starting a project. my cabal file specifies
build-depends: base <4.8, criterion >=1.0 && <1.1, memoize <=0.6
criterion is in the sandbox of current directory.
If I check with ghc-pkg list memoize it will show.
C:/Program Files/Haskell Platform/2014.2.0.0\lib\package.conf.d: (no packages)
C:\Users\Song\AppData\Roaming\ghc\x86_64-mingw32-7.8.3\package.conf.d: memoize-0.6
memoize is globally available.
However, when I run cabal repl, cabal complains memoize is missing. Do I have to re-install the package in the sandbox in this case?
Yes, you do. The purpose of sandboxes is to work independently of the user package database, not in addition to it. You can override this by adding back the user package database with the --package-db flag, but it isn't a recommended workflow.

Cabal: rebuild package to use newer libraries

I'm using Ubuntu 14.10 with GHC 7.6.3 and cabal installed via the Ubuntu package installer, and trying to use the Heap data structure, which I naively installed using:
cabal install heap
As soon as I started importing the library into my code, I got the following linking error:
...
Loading package primitive-0.5.0.1 ... linking ... done.
...
Loading package heap-1.0.0 ... linking ... done.
...
Loading package primitive-0.5.2.1 ... linking ... done
...
GHCi runtime linker: fatal error: I found a duplicate definition for symbol
hsprimitive_memset_Word32
whilst processing object file
/home/simon/.cabal/lib/primitive-0.5.2.1/ghc-7.6.3/HSprimitive-0.5.2.1.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry.
This answer notionally explains what to do, but the instructions are not specific enough for me to follow.
How do I get Heap to use primitive-0.5.2.1 (I'm assuming that this lightly used library is the one that is out of date), or should I be doing something completely different?
One solution might be to specifically install an earlier version of heap:
cabal install heap-0.6.0
You might have to first unregister heap-1.0.0.
Another option is to blow away your ~/.ghc directory. Of course, you will have to reinstall cabal packages.
I think the best option is to start using cabal sandboxing for your projects.
Edit: heap-1.0.0 contains QuickCheck tests and thus brings in all of the QuickCheck dependencies. To install that version without QuickCheck, try this:
In a new directory, run cabal get heap-1.0.0
cd heap-1.0.0
Edit heap.cabal and remove the Build-Depends: line
Run cabal install

Haskell install and use packages

I want to use in my haskell project xml library (http://hackage.haskell.org/package/xml)
I downloaded it.then try to build and install:
runhaskell Setup.hs configure
runhaskell Setup.hs build
runhaskell Setup.hs install
All ok. There are no errors. When i try import modules from this lib to my project, for example:
import Text.XML.Light.Cursor
I get error:
/home/shk/dev/src/XMPP.hs:8:8:
Could not find module `Text.XML.Light.Cursor':
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
What's wrong? How can i install and use library in haskell?
Thank you.
Copying from the mailing list:
First thing is to do 'ghc-pkg list'.  If your package doesn't show up
then it's not installed, according to the package registry.  'cabal
install' should have registered it.  If it is in the list, then it
depends how you're building.  If you use ghc manually, then you have
to give '-package xyz'.  If you use 'ghc --make', ghc will
automatically add the -package for you.  If you use cabal, you put the
package in the dependencies, and 'cabal build' will add -package for
you.
If the package has parens, then someone hid it, and you'll have to do
'ghc-pkg expose' on it.  If you're doing everything else right and it
still doesn't find the package, then you can run ghc -v and it'll
print lots of details.  It might have something about 'hiding xyz
because of ', which means you're depending on
libraries that expect different versions of the underlying library.
You can sometimes get out of this by carefully upgrading or
downgrading certain libraries.

Resources