How do I use the gloss-examples package? - haskell

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).

Related

How to install an library in Haskell?

I try to use
Control.Monad.Extra.andM
import Control.Monad.Extra (andM)
but has an error:
Could not find module ‘Control.Monad.Extra’
Perhaps you meant
Control.Monad.Catch (needs flag -package-key exceptions-0.10.4)
Control.Monad.Error (needs flag -package-key mtl-2.2.2)
Control.Monad.Except (needs flag -package-key mtl-2.2.2)not found
This error does not make sense.
According to
https://cabal.readthedocs.io/en/3.6/installing-packages.html#installing-packages-from-hackage
3.2.1. Installing packages from Hackage
The cabal tool also can download, configure, build and install a Hackage package and all of its dependencies in a single step. To do this, run:
$ cabal install [PACKAGE...]
To browse the list of available packages, visit the Hackage web site.
Which says "in a single step", but in my experience this is too complicated and actually I have no idea how to install Control.Monad.Extra .
Usually, when a Haskeller want to install a specific library/package like this, how do you do this? There's no adequate documentations, it seems.
How to install an library in Haskell?
You don't. You should just depend on them, and then let Cabal worry about any installations that may need to be done. I.e., as you wrote
Go to the Hackage page and study which exact library to be used.
*.cabal file -> build-depends: extra >=1.7.10
This is the crucial step. Your own Cabal file is the way to both specify what libraries are needed right now, as well as ensuring that everything will still work in the future. This file needs to specify both the packages you require, as well as the modules you're defining yourself.
Probably you don't actually need >=1.7.10, but it can't hurt much to be specific there. Standard practice is to add both lower and upper bounds on the x.y level, i.e. you'd use extra >=1.7 && <1.8, and then push the upper boundary as new versions come out. Arguably this is a bit overcautious; if you only use some simple tools from a package that is unlikely to have breaking changes in the future then it may be less trouble to just leave the upper boundary out.
$ cabal install extra
You've already specified that extra is needed for your project, no need to state that again. Instead, simply build your own project now.$ cabal buildor, to get a GHCi prompt with your modules,$ cabal replor, if you have an executable with a main that you wish to execute$ cabal runor if you want to install that executable (and only then)$ cabal installCabal will then automatically figure out that extra-1.7.10 should be installed first.
(In old Cabal it would still have been necessary to run cabal install --dependencies-only first.)
Ok Self-Answered. Comment me if the information is wrong.
1. Go to the Hackage page and study which exact library to be used.
In this case, it seems extra-1.7.10.
2. *.cabal file -> build-depends: extra >=1.7.10 (among other libs)
3. $ cabal install extra
Error:
cabal: Cannot build the executables in the package extra because it does not contain any executables. Check the .cabal file for the package and make sure that it properly declares the components that you expect.
Well, I did for sure.
4. cabal install extra --lib
Finally works, but the documentation never said this.
Am I correct?
`
Is this the only method? or any other smarter way?

Stack: How can I use a multi-package dependency in `Setup.hs`?

I have a stack multi-package project where the "multi-package" is zip-conduit-0.2.2.2 (I needed to tweak some dependency versions to get it to compile with nightly-2015-10-12).
I use zip-conduit in the main package and I also want to in Setup.hs in order to be able to package up zip files.
I have build-type: Custom in my cabal file and stack build attempts to build Setup.hs. The problem is that building Setup.hs cannot find the dependency zip-conduit-0.2.2.2.
Can I use a multi-package dependency in Setup.hs? If so how? and if not, what is my alternative?
Note: I have seen this reference https://github.com/commercialhaskell/stack/pull/899, but I don't understand it.
It looks like you need to set the explicit-setup-deps setting to true for that package. It's unfortunate that Stack can't handle this situation automatically, but without dependency information in .cabal files, there seems to be no alternative.
See the linked issues from the documentation if you're interested in the history here.
I don't think it is possible to declare package dependencies for Setup.hs itself.
Some ideas:
Require that the dependent packages have already been installed.
Have Setup.hs shell out to an external command to perform the zipping, and just require that the external command has to exist.
Make the installer program an additional exe target in the cabal file. Before proceeding with the build of the library, Setup.hs can build the installer program target, then build the library, then use the built installer exe to install the library.

cabal build-depends: how to find?

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.

c2hs not getting installed / registered correctly

When I run cabal install c2hs, it seems to finish correctly, but doesn't register the package. The package seems as if it's not even installed: it doesn't show up in ghc-pkg list, and rerunning cabal install c2hs goes through the same install procedure, instead of saying "All the requested packages are already installed".
I'd much appreciate any help getting this up and running. I'm using the prebuilt GHC 7.4.1 binary.
cabal install output: http://pastebin.com/CRUii8mm
imports are defunct: http://pastebin.com/r0aypxRA
Thanks in advance!
I believe c2hs is an executable, not a library. The cabal install output that you provided shows that the execeutable is placed in your private .cabal/bin directory.
The C2HS module has been removed from newer versions of c2hs, since sometime prior to c2hs-0.15. If you check out the c2hs source tree, you could find it by going back through the revisions. Or some other libraries include it. There's more information in this trac ticket. C2hs is moving towards making the functions in C2HS.hs completely unnecessary, although they aren't quite there yet (floating-point formats in particular need to be manually marshalled).

Which Haskell package contains given module

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.

Resources