I have the following RPM packages installed on my Fedora 28 system:
ghc-ghc-8.2.2-66
ghc-containers-0.5.10.2-66
According to hackage the set module should be included in the given RPMs. However trying to import Data.Set results in
<no location info>: error:
Could not find module ‘Data.Set’
Perhaps you meant Data.Int (from base-4.10.1.0)
Did I miss something to install? How can I check which modules are available?
Edit:
$ ghc-pkg list
/usr/lib64/ghc-8.2.2/package.conf.d
base-4.10.1.0
ghc-prim-0.5.1.1
integer-gmp-1.0.1.0
rts-1.0
How do I register a module?
I would skip the operating system packages and go with stack:
$ wget -o get-stack.sh https://get.haskellstack.org/
$ chmod +x get-stack.sh
$ ./get-stack.sh -d ~/.local/bin
$ echo 'export PATH="~/.local/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ stack --version
Version 1.7.1, Git revision ...
Then use stack ghc to run GHC; the first time it will install this:
$ stack ghc
Writing implicit global project config file to: ...
Note: You can change the snapshot via the resolver field there.
Using latest snapshot resolver: lts-12.9
Downloaded lts-12.9 build plan.
Preparing to install GHC to an isolated location.
For anyone new like me who finds this, you need to add containers to your package.yaml dependencies in order to import Data.Set. My package.yaml dependencies looked like this to get a Data.Set import to work:
dependencies:
- base >= 4.7 && < 5
- containers > 0.6
Then you can import Data.Set in your file like
import Data.Set (Set)
import qualified Data.Set as Set
ghc-containers contains only the shared library (.so) for compiled programs that are linked to it. If you wish to use the library in development, install ghc-containers-devel:
$ dnf install -y ghc-containers-devel
$ ghci
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.Set
Prelude Data.Set>
Related
I'm on macOS running stack/GHCi version 8.4.3:
import Test.QuickCheck fails at both the GHCi prompt and in my .hs files. Either way I'm told it's not found.
GHCi Prelude>
<no location info>: error:
Could not find module ‘Test.QuickCheck’
It is not a module in the current program, or in any known package.
in .hs file >
"Could not find module ‘Test.QuickCheck’ '
The source code is on this page but I'm not sure how to install a new package into stack manually. From my brief reading when I googled "install Haskell package" it suggests installing a cabal package universally is a bad idea. Not sure this is a cabal package, and in any case it would be good to be able to import it for any project I think in my case.
The modern way to do this for a quick ghci session is to use cabal repl and add a dependency on QuickCheck:
% cabal repl --build-depends QuickCheck
> import Test.QuickCheck
Test.QuickCheck> -- ^_^
For longer-term programming (i.e. not just quick tests of stuff in ghci), the modern way is to create a cabal package and add QuickCheck to the build-depends section in the *.cabal produced:
% mkdir fancy-package
% cd fancy-package
% cabal init
<follow prompts>
% $EDITOR fancy-package.cabal
<find build-depends: and add, for example, QuickCheck ^>= 2.14 to the list>
% cabal repl
*Main> import Test.QuickCheck
*Main Test.QuickCheck> -- ^_^
I could not add System.Random module to use it my source haskell file.
import System.Random
This is the error produced by stack ghc:
/Users/admin1/Haskell/PROJECTS/L4/src/Lib4.hs:32:1: error:
Could not load module ‘System.Random’
It is a member of the hidden package ‘random-1.1’.
You can run ‘:set -package random’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
32 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
Failed, five modules loaded.
Thank you very much in advance.
P.S. I am using Stack and GHC versions: Version 2.3.1, Git revision x86_64 hpack-0.33.0, ghc-8.8.3 on Mac OSX
As the error says:
It is a member of the hidden package ‘random-1.1’.
This likely means that you did not list it in the build-depends, and thus it is not exposed to your modules.
You can alter the .cabal file, and add it, for example:
-- project.cabal file
-- …
executable …
-- …
build-depends:
base >= 4.7 && < 5
, random >= 1.1
-- , …
Here are my version info:
cabal-install version 1.24.0.2
compiled using version 1.24.2.0 of the Cabal library
On Ubuntu 18.04
$ ghci
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
Prelude> import Control.Monad.Par
<no location info>: error:
Could not find module ‘Control.Monad.Par’
Perhaps you meant
Control.Monad.Fail (from base-4.9.1.0)
Control.Monad.Fix (from base-4.9.1.0)
Control.Monad.RWS (needs flag -package-key mtl-2.2.1#mtl-2.2.1-BLKBelFsPB3BoFeSWSOYj6)
Would appreciate any help on how to get Control.Monad.Par to work.
In general, Could not find module ‘...’ means you don't have the package installed1. You can search the module name on hayoo to get the package name, and then do:
cabal install [package name]
Or if you're using Stack for your project (recommended), you can add the package name to the build-depends section in your *.cabal file.
1It could also mean you misspelled the module name, the package was installed incorrectly, GHC isn't looking for the package in the place it was installed, or some other weird thing is going on, but I won't go into that.
I'm trying to use Posgres and a cabal sandbox for a new project. I've got postgresql-simple installed, as evidenced by installation outputs:
$ cabal install postgresql-simple
Resolving dependencies...
All the requested packages are already installed:
postgresql-simple-0.4.10.0
Use --reinstall if you want to reinstall anyway.
Notice: installing into a sandbox located at
/Users/inaimathi/projects/hs-test/.cabal-sandbox
but when I try to import the library in ghci, I get the error
ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help
Prelude> import Database.PostgreSQL.Simple
import Database.PostgreSQL.Simple
<no location info>:
Could not find module ‘Database.PostgreSQL.Simple’
It is not a module in the current program, or in any known package.
Prelude>
Can anyone point out what I'm doing wrong?
You need to start GHCi with a -package-db=... flag pointing to /Users/inaimathi/projects/hs-test/.cabal-sandbox
so
ghci -package-db=/Users/inaimathi/projects/hs-test/.cabal-sandbox
or thereabouts...
I encounter a strange situation in GHCI, don't know if anyone observed similar case. For some module, when I have it in the search path both by -package-conf, and also by -i, GHCI fails when I try to import the module with 'module is not loaded: FooModule'.
:module loads it fine however
or I can do :load FooModule, :m to clear the import list, and then import FooModule
or I can remove the path from -i and then it imports fine
Tracked this to be the otherwise -> modNotLoadedError m loc case in GHC, where otherwise ~ modulePackageId = this_pkg (the meaning of which I don't know).
This is not entirely systematic, there are some module which are both in package and source path, but can be imported.
GHC only knows about packages that are installed. To see which packages are installed, use the ghc-pkg list command:
$ ghc-pkg list
/usr/lib/ghc-6.12.1/package.conf.d:
Cabal-1.7.4
array-0.2.0.1
base-3.0.3.0
base-4.2.0.0
bin-package-db-0.0.0.0
binary-0.5.0.1
bytestring-0.9.1.4
containers-0.2.0.1
directory-1.0.0.2
(dph-base-0.4.0)
(dph-par-0.4.0)
(dph-prim-interface-0.4.0)
(dph-prim-par-0.4.0)
(dph-prim-seq-0.4.0)
(dph-seq-0.4.0)
extensible-exceptions-0.1.1.0
ffi-1.0
filepath-1.1.0.1
(ghc-6.12.1)
ghc-prim-0.1.0.0
haskeline-0.6.2
haskell98-1.0.1.0
hpc-0.5.0.2
integer-gmp-0.1.0.0
mtl-1.1.0.2
old-locale-1.0.0.1
old-time-1.0.0.1
pretty-1.0.1.0
process-1.0.1.1
random-1.0.0.1
rts-1.0
syb-0.1.0.0
template-haskell-2.4.0.0
terminfo-0.3.1
time-1.1.4
unix-2.3.1.0
utf8-string-0.3.4