Software
Home Ordering Info Lecture Slides Demos Bugs/Errata Software Solutions to Exercises


The code originally used in The Haskell School of Expression relied on a graphics library called SOEGraphics, which in turn depended on a more primitive, but not-very-portable, graphics library called HGL.

We now recommend down-loading the source code for SOE below, which imports a new graphics library called simply SOE.  The SOE library uses a highly-portable graphics package based on OpenGL.  Alternatively, there is a version based on Gtk, although it is not quite as portable as the former.  In both cases we recommend using GHC (and GHCi) as the Haskell compiler (and interpreter).  Both methods for installing SOE are described below.

Acknowledgements:  Thanks to Paul Liu for writing the GLFW package, and to Duncan Coutts for writing the Gtk2Hs library for SOE (some of the code from that is in fact used in GLFW).

Note:  If you encounter any problems with the graphics packages, please send email to both Paul Liu (hai.liu@yale.edu) and Paul Hudak (paul.hudak@yale.edu).

OpenGL

This is the recommended implementation.  It depends on the OpenGL and GLFW packages for better cross-platform support than was previously available.

Step 1:

Note:  Users of GHC 6.6 through GHC 6.8.3 should skip directly to Step 2.

For Linux and OS X users, you may download OpenGL from:
    http://hackage.haskell.org/cgi-bin/hackage-scripts/package/OpenGL
and follow the usual cabal package installation steps:

       runhaskell Setup.hs configure
       runhaskell Setup.hs build
       runhaskell Setup.hs install 

For Windows users, you may follow the installation instructions at:
   http://netsuperbrain.com/blog/posts/freeglut-windows-hopengl-hglut/
Be prepared that these steps are much more complicated.
(If possible, we recommend using GHC 6.8.3 or earlier to avoid this inconvenience.)

Step 2:

To install SOE, first download and unzip the following files:

bullet

The latest SOE source code:
http://www.cs.yale.edu/homes/hl293/download/SOE-20071003.zip

bullet

The GLFW package on which it depends:
http://hackage.haskell.org/packages/archive/GLFW/0.3/GLFW-0.3.tar.gz,
or, better yet, in zip format:
http://www.cs.yale.edu/homes/hl293/download/GLFW-0-3.zip

GLFW (see http://haskell.org/haskellwiki/GLFW) comes as Haskell package that must be installed before running SOE code.  It is a Haskell front-end for the GLFW  OpenGL framework, and provides an alternative to GLUT for OpenGL-based Haskell programs.

The second download is a Haskell Cabal package that can be installed in the following way:

  1. Make sure ghc (or ghc.exe) is in your PATH environment.  On Windows
     machines, you also need the gcc-lib directory to be in your PATH.

  2. unpackage the source, go to its top directory where file GLFW.cabal exists, and type:

        runhaskell Setup.hs configure

     Or, if you want to install the Haskell package to your user's directory (DIR)
     instead of the system default directory:

        runhaskell Setup.hs configure --user --prefix=DIR 
 
  3. To build the Haskell module, type:

        runhaskell Setup.hs build

  4. To install the Haskell module, type:

        runhaskell Setup.hs install

Note that GLFW requires Cabal 1.2 or later to build, which comes as default in GHC 6.8 and later. If you are using GHC 6.6, please compile and install Cabal 1.2 (and also FilePath which Cabal 1.2 depends on) first before installing GLFW.

The SOE source code requires no installation once GLFW is installed.  Simply place the SOE code where you want it, load any module into GHCi, and hope for the best!

However, on MacOS X, you'll have to use the "EnableGUI trick" from wxHaskell (see http://wxhaskell.sourceforge.net/building-macosx.html).  The software for that trick is included in the SOE download, so all you need to do is the following:

  1. First compile EnableGUI.hs to binary as follows:
        ghc -c -fffi EnableGUI.hs
    Note: on some systems it is necessary to include a -framework option, like this:
       
    ghc -framework ApplicationServices -c -fffi EnableGUI.hs

  2. Then run your SOE programs in GHCi like this:
        ghci Draw.lhs EnableGUI
        *Draw> :m +EnableGUI
        *Draw EnableGUI> enableGUI >> main0
     
    Otherwise, GHCi will not be able to fully activate the Graphics Window.  (Fully compiled SOE programs do not suffer from this anomaly.)

 

Gtk2Hs

Instead of using OpenGL / GLFW, an alternative way to run SOE source code is to use the module Graphics.SOE.Gtk instead of the SOE.hs included in the source above.  To do this, follow the installation instructions for Gtk2Hs at http://www.haskell.org/gtk2hs, then import the module Graphics.SOE.Gtk instead of SOE.hs in your code.

Although both platforms have their advantages from a graphics point of view, keep in mind that:

  1. Gtk2Hs is bigger than GLFW (8.5MB vs. 120KB download, and 84MB vs. 1.8MB installed).

  2. Gtk2Hs for Windows requires exactly version 6.6.1 of GHC.

  3. You can try compiling Gtk2Hs from source for other versions of GHC, but that is sometimes not so easy. 
    Unfortunately, it is a must for the Mac and any Linux distribution not supported by Gtk2Hs.