I know a Haskell module name, but I can't figure out in what package it is defined. This is bad because I can't compile without a package exposing this module.
Specificaly it is Text.Regex that I can't locate, but I would like to know how to solve that problem in general.
http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html
ghc-pkg find-module Text.Regex
But that only works for (a) recent GHCs, and (b) packages installed on your system.
You can also grep through the package file (e.g. /usr/lib/ghc-6.8.2/package.conf) to see what's installed.
You can also use either the haskell API search engines hoogle or the hackage search engine hayoo.
Text.Regex is in the package regex-base, and a few others built on top of it.
If you're using Cabal and you have the package installed, you can just try to compile it with cabal build, and Cabal will inform you of which package you forgot to add to your dependencies:
Main.hs:1:8:
Could not find module `Text.Regex':
It is a member of the hidden package `regex-compat-0.93.1'.
Perhaps you need to add `regex-compat' to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
The best tools are:
hoogle; or
hayoo.
Both are search engines for Haskell modules and functions.
If you are using Debian and the Debian-provided packages, there is a global documentation index at /usr/share/doc/ghc-doc/html/libraries/index.html which lists the package in the last column.
Related
I've installed the Gloss graphics library with cabal. I also installed the gloss examples package.
Now I want to test the examples. This may seem like a silly question, but how do I actually use the package gloss-examples? I understand I can now import the gloss library to a haskell module but how do I test the gloss-examples I installed i.e. how do I use the gloss-example package?
Building gloss-examples produces a handful of executables, as specified by the Executable entries in the .cabal file. (Another telltale sign of executable-only packages is the lack of entries for modules at the front page of the Hackage docs.) In Linux, the default destination of such executables is ~/.cabal/bin. According to the answers to this question, in OS X the default is ~/Library/Haskell/bin/cabal, unless you are using the Homebrew package manager, which changes it to ~/.cabal/bin. In Windows, it is %APPDATA%\cabal\bin. See also: the Installation paths section in Cabal's user guide.
The gloss-examples package does not install any modules and you do not work with it as a library. Instead, it builds executables (see here) under the names gloss-*. Just run those executables which are wherever you have cabal installing the binaries (typically $HOME/.cabal/bin).
I'm attempting to start a new project using the Snap web framework. I used snap init to get my basic skeleton working. I also put http://www.stackage.org/lts/cabal.config next to my .cabal file. I didn't uncomment the line to use Stackage exclusively. So I tried to build and it failed and couldn't find the version of lens required by my .cabal file. The cabal.config file from Stackage specifies a version of lens that is not the same as the one in my .cabal file. So I deleted every constraint from my package list and did the usual cabal install --only-dep -j8 --enable-test and it worked!
However, I have always been told that package versions should be constrained. So when working with Stackage is it okay to leave package versions unconstrained? Should I downgrade my packages to the ones available in Stackage instead?
As far as I understand a cabal.config file specifies a set of dependencies with the specific versions that satisfy dependencies, so how does Stackage work? Is it just a subset of packages from Hackage that are proven to be compatible? Do they host their own packages or rely on Hackage for downloads?
Thanks in advance :)
Both options are available. The default option is what you did, and still goes to hackage to get the packages. You just added a filter to your cabal that prevents you from using any version of a package included in Stackage that was not tested to work together with all of the other packages.
The other option is to simply point your cabal repo to a Stackage url, and then you will download packages directly from the Stackage server. That server will only serve packages that are known to work together, so there is no need for additional constraints in your cabal file. I actually prefer this way of working.
In both cases, if you have additional constraints in your cabal file that are incompatible with the Stackage restrictions, your build will fail. If you use the first option, you will get dependency conflicts. When using the second option, the Stackage server will simply report that it does not have that specific package/version.
How can I find out what needs to go into the module.cabal build-depends? I mean, some modules may already be part of the Haskell platform whilst others may not? How to I find out/know what I must write here so that the module I offer will install with cabal on the majority of Haskell installations "out there"?
My situation is that I have it working on my systems, but cannot remember for what import I actually had to install an other module and what was part of the Haskell Platform that I use. How do I now best find the way from my situation to a cabal installable package?
If you use Cabal to build your project, it will only look at the modules listed in the .cabal file, even if you have other modules installed locally.
So all you have to do is run it as is (with nothing in the depends declaration) and it will give you an error for each module you need to specify. I think the error even tells you the name of the package.
I'm using cabal to download Haskell packages.
The following works:
> cabal install JSON
It gets Text.JSON
However, this fails:
> cabal install Data.List.Key
cabal: "Data.List.Key" is not valid syntax for a package name or package
dependency.
What is the syntax problem here? How do I make cabal get Data.List.Key? In general, for a package of name X.Y, what name does cabal install need in order to find the package? (I'm confused why cabal install JSON gets Text.JSON, and not Foobarbaz.JSON)
The cabal install command uses package names. Package names are different from module names. If you look on the hackage page for the text package, you'll see that the package name is "text", but it exports a module called Data.Text (amongst others). Packages can export any number of modules and there does not have to be any relationship between the name of the package and the name of the modules it exports.
If you know a package you want, but you don't know the exported modules, look on the hackage page for that package. To do this, I go to "http://hackage.haskell.org/package/" in my browser. I've gone there so many times, it auto-completes very quickly, then I add the package name to the end of that url. If I don't know the exact package name, then I just go to that page and search the package list for what I want.
The converse situation where you know what module you want but don't know what package provides it is a little more difficult. In this case, I rely on the wonderful Haskell search engine Hoogle.(Another one Hayoo, has been offline for a while.)
Packages can include more than one module. There is no rule about how module names map to package names.
If you know the module name and want to find the package it is in, browse it's hackage documentation.
The url of the module description contains the package name after the package part, e.g. the url of Linear.Quaterion is
http://hackage.haskell.org/package/ linear-1.21.1 /docs/Linear-Quaternion.html
On that page the package name is also shown in the top left end.
If you know the package name, you can query which modules are included with
cabal info <package name>.
Today when I tried to compile my code in Geany I got this error
Could not find module `Control.Monad.Reader':
it was found in multiple packages: monads-fd-0.1.0.1 mtl-1.1.0.2
Compilation failed.
I get the same for the Writer monad; I thought I should remove one of those packages, but I do not want to break other packages, so now what should I do, yesterday everything worked without any problem.
It looks like you have recently installed monads-fd, perhaps as a dependency of something else you installed. Both monads-fd and mtl packages contain the module Control.Monad.Reader, so GHC doesn't know which one to use when you compile some code that imports it. You need to resolve the ambiguity somehow:
If you are using GHC or GHCi directly
either use a -hide-package <package> flag on the command line to hide one of the packages, or
hide the package by default using ghc-pkg hide <package>. You may need to use ghc-pkg --user hide <package> if the package was installed in your home directory (the default on some platforms).
You can use Cabal, and say exactly which one of the conflicting packages you depend on using the build-depends field in your .cabal file
I encountered a similar problem recently, and it was suggested that I run ghc-pkg hide {x} where '{x}' is the name of one of those packages. It worked in my situation.