Can't load Graphics.Gloss in Haskell


I wanted to play around with Pong.hs. I downloaded the .hs file, but when I opened it in Sublime Text (with the Haskell plugin) I was told that Graphics.Gloss and Graphics.Gloss.Interface.Pure.Game were missing.

> cabal install Graphics.Gloss

couldn't find Graphics.Gloss. Hoogle found it for me. One of the comments in the file mentioned compiling Gloss. So I tried

> cabal install Gloss

which succeeded -- although I don't understand why. The Sublime Text plugin was also happy. But when I tried to load the code into WinGHCi, I got

Pong.hs:22:1: error:
    Failed to load interface for ‘Graphics.Gloss’
    Use -v to see a list of the files searched for.

Pong.hs:23:1: error:
    Failed to load interface for ‘Graphics.Gloss.Interface.Pure.Game’
    Use -v to see a list of the files searched for.

I'd appreciate suggestions about what to try next.


Show source
| haskell   2017-01-06 22:01 1 Answers

Answers ( 1 )

  1. 2017-01-06 22:01

    First, some background: Graphics.Gloss is the name of a module -- a collection of named code snippets. gloss is the name of a package -- a collection of modules. cabal install accepts a package name and installs that package into a package database -- a collection of packages.

    Now we have the vocabulary we need to discuss what you observed, and how you can make progress.

    cabal install Graphics.Gloss couldn't find Graphics.Gloss

    Right, Graphics.Gloss is a module, not a package. The gloss package provides that module. I don't know of a reliable tool for mapping module names to the packages that provide them, but Hoogle and Hayoo will both tell you the package name associated with any of their search results. (I don't class them as "reliable" because they index only a subset of Hackage.)

    cabal install Gloss succeeded

    Although the package is named gloss and not Gloss, cabal install attempts to Do The Right Thing, installing a surrogate package if it differs only in case.

    when I tried to load the code into WinGHCi, I got [an error]

    I would bet that Sublime Text and WinGHCi are using different package databases; for example, perhaps you are using a cabal sandbox and Sublime Text has picked that up. You could try running these two commands and comparing their output:

    cabal sandbox hc-pkg list gloss
    ghc-pkg list gloss

    Note that the former will behave differently when run from different directories and in different environments, so take care to run it using the same steps you used to run cabal install Gloss!

    If you have installed gloss into a sandbox, the first command should show you the location of the package database associated with that sandbox and the version of the gloss library installed there. The second should show no results. If that is the case, you can try running WinGHCi using an environment appropriate for the sandbox; for example, something like

    cabal exec winghci

    should do the trick (if winghci is the command that starts WinGHCi -- no Windows box here, so I don't know for sure). Again, being in the right directory with the right environment variables set is important for this command to work, so make sure you run it following the same steps you did for running cabal install Gloss and the previous package database query.

◀ Go back