So I've been installing packages in Haskell with Cabal. I can't see any documentation for most of these (in general), and I've been told that one of the best ways to learn haskell is just to read the code in the package, work out what it does, and play with it in GHCi or something. But how do you do this? After installing these packages into a sandbox or something, I can't even see what the module names are, let alone their source code - how do I find this information?
I usually look up the documentation for Hackage packages online, at https://hackage.haskell.org/package/nameOfPackage
. It has (unless broken, which alas happens) links to documentation for each module, as well as links to the source code inside that.
EDIT on broken docs:
Unfortunately Hackage's doc building system sometimes fails for whatever reason, usually resulting in the list of modules being just plain text with no links. In that case, a good idea is to check out the list of links to older package versions: often one of them works.
There's also the problem that some libraries aren't very well documented at all, in which case all you get is type declarations, type signatures and links to the source. (But check out if there are links to other docs on the package frontpage.)
see any documentation
The cabal haddock
command will build documentation for you and place it in dist/doc
. If you use --enable-documentation
(or set documentation: True
in ~/.cabal/config
), cabal install
will also compile the documentation for all your packages in ~/.cabal/share/doc
. You may also want to use --hyperlink-source
or set hyperlink-source: True
in the haddock
section of ~/.cabal/config
.
read the code in the package
You can cabal unpack
a package to get the source. For package foo
version x.y
, the source will be placed in a directory named foo-x.y
by default.
play with it in GHCi
Once you have the package source, you can navigate into the directory and run cabal repl
to get a ghci instance with all the package modules loaded.
see what the module names are
The Modules:
section of cabal info
will be of interest here. Once a package is installed, you can also use ghc-pkg describe
to get similar functionality. (The primary difference here is about which packages are known; cabal info
will know about what's on Hackage/whatever package repository you have configured cabal
to use, even if the package isn't installed yet, while ghc-pkg
will know about any package you have installed, even if that package didn't come from Hackage.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With