How do you import Data.Heap? - haskell

Sorry for such a dumb question. I'm trying to import Data.Heap, but I get this error message:
> import Data.Heap
<no location info>: error:
Could not find module ‘Data.Heap’
Perhaps you meant
Data.Map (from containers-0.5.7.1#containers-0.5.7.1)
Haven't had trouble with other imports.
Thanks.

As was described in the comments, you need to install the package which contains the module Data.Heap. (See this related question on the difference between packages and modules in Haskell)
On the Hackage page, in the upper left-hand corner you will see the name and version of the package you are looking at:
If you are using stack, then add heap to your build-depends section of project.cabal file, and rebuild. If you are just using cabal, simply run cabal install heap to get the most recent version of the package installed on your system.

Related

How to use cabal install for regular expression package installation?

Am working through Real World Haskell and am trying to install regex-posix-0.95.2 from an untar[ed] package by simplying running
cabal install
I then see:
Text/Regex/Posix/Wrap.hsc:141:1: error:
Could not find module ‘Text.Regex.Base.RegexLike’
There are files missing in the ‘regex-base-0.93.2’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
141 | import Text.Regex.Base.RegexLike(RegexOptions(..),RegexMaker(..),RegexContext(..),MatchArray)
Despite the fact that I can load this in ghci with
Prelude> :module Text.Regex.Base.RegexLike
Prelude Text.Regex.Base.RegexLike>
Prelude> import Text.Regex.Base.RegexLike(RegexOptions(..),RegexMaker(..),RegexContext(..),MatchArray)
Prelude Text.Regex.Base.RegexLike>
and see it in the module-system.
[warrick#warrick-pc regex-posix-0.95.2]$ ghc-pkg find-module Text.Regex.Base.RegexLike
/usr/lib/ghc-8.6.2/package.conf.d
regex-base-0.93.2
Why is this failing?
What are some more general tips and tricks when trying to debug cabal failures you'd recommend (as this is one instance of many issues I'm consistently having with Cabal)?
This is a linking issue. For example, some distributions like Arch use dynamic linking by default, without static libraries, but without additional configuration, cabal tries to link statically, which results in the kind of message you are seeing. For more information: https://wiki.archlinux.org/index.php/Haskell

Module can not be imported after installing via cabal

I tried using the primes module in Haskell and after running
$ cabal install primes
Resolving dependencies...
Notice: installing into a sandbox located at /home/christoph/.cabal-sandbox
Downloading primes-0.2.1.0...
Configuring primes-0.2.1.0...
Building primes-0.2.1.0...
Installed primes-0.2.1.0
I tried making a file with
import Data.Numbers.Primes
at the top, but every attempt to load it failed with the error message:
Could not find module ‘Data.Numbers.Primes’
Use -v to see a list of the files searched for.
The question: what am I missing here? there must be something wrong with this way of using it right?
After reading Haskell: where is Data.Numbers.Primes library? I also tried:
import Data.Primes
import primes
import Primes
but none of them worked.
Thank you in advance, any help is most welcome
Because you are installing the primes package to a sandbox, you will need to run the compiler with awareness of the sandbox. cabal offers the exec command for this, so e.g.
echo import Data.Numbers.Primes >foo.hs
cabal exec ghci foo.hs
from within the sandbox should work.

Haskell: where is Data.Numbers.Primes library?

I tried importing Data.Numbers.Primes
import Data.Numbers.Primes
runhaskell gave me:
5.hs:1:8:
Could not find module `Data.Numbers.Primes'
Use -v to see a list of the files searched for.
ghci gave me:
<no location info>:
Could not find module `Data.Numbers.Primes'
It is not a module in the current program, or in any known package.
I tried to install Data.Numbers.Primes through cabal, but I got:
cabal update
...
cabal install Data
cabal: There is no package named 'Data'.
You may need to run 'cabal update' to get the latest list of available
packages.
cabal install Data.Numbers.Primes
cabal: The file does not exist 'Data.Numbers.Primes'.
help?
The package you're looking for is called primes.
There's no rule that the package will be called the same as its top-level module name. Typically, packages put themselves under whatever makes sense, but that's pretty much arbitrary. When in doubt, Hackage search helps.

Cabal failing to install vector-space package

When I try to install the spacepart package using cabal install it tries to compile a dependency vector-space but when vector-space tries to compile a module it exports "Data.LinearMap" I get the error "Not in scope type constructor or class "HasTrie". After I did some digging HasTrie is a class exported by the MemoTrie package. Thing is I have MemoTrie installed and MemoTrie exports "HasTrie". What is wrong here?
Also this stack overflow post doesnt help so this isnt a duplicate question: Haskell package vector-space fails at compile time
-Thank you for your time
As far as I can see from browsing on Hackage, spacepart is fixed to use a very old version of vector-space (0.5.*), and that version's Data.LinearMap contains the suspicious import line
import Data.MemoTrie ((:->:)(..))
which simply doesn't import HasTrie. My guess is that at some time in the past, this actually worked, because (:->:) is a data family defined inside HasTrie, but that GHC has since been changed so it doesn't.
Possible dirty fix: I note that until 0.5.2, it simply says
import Data.MemoTrie
I just tried installing with
cabal install spacepart vector-space-0.5.2
and it seemed to work.

Haskell Hidden Packages: Data.HashSet

I'd like to use Data.HashSet in Haskell. So I put import Data.HashSet at the beginning of my program. GHCi complains: Could not find module Data.HashSet.
My questions are:
How can I get Data.HashSet to work?
I've read somewhere that this is part of a hidden module or package. Why is the module hidden? Does "hidden" mean that I should not use it?
If I should not use it, is there a better alternative for a haskell data structure with a near-constant lookup time?
Data.HashSet is a module in the unordered-containers package, and also in the hashmap package. If you have either package installed,
import Data.HashSet
should work out of the box, since it is an exposed module of both packages. To install it (using unordered-containers, since that is the commonly used one),
cabal update
cabal install unordered-containers --dry-run
-- check that it wouldn't reinstall anything, if all's fine
cabal install unordered-containers

Resources