Home > tech > The Haskell School Of Expression: Getting Started on Ubuntu

The Haskell School Of Expression: Getting Started on Ubuntu

PC sent me a copy of Hudak’s The Haskell School of Expression for my birthday. I was trying to get started with some of the code in the book and could not find a good writeup on it. Here is how I got it going on my Ubuntu Gutsy laptop.

First, install GHC and HGL as:

sudo apt-get install ghc6
sudo apt-get install libghc6-hgl-dev

Then, copy the following code to a file simple.hs somewhere on the disk. This code is from Chapter 3 of the book.

import Graphics.SOE
main0
   = runGraphics $
     do w <- openWindow "My First Graphics Program" (300, 300)
        drawInWindow w (text (100, 200) "HelloGraphicsWorld")
        k <- getKey w
        closeWindow w

Launch GHC interpreter and load the code into it.

$ ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6.1, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type : ? for help.

Loading package base ... linking ... done.
Prelude> :l /path/to/simple.hs
[1 of 1] Compiling Main             ( /path/to/simple.hs, interpreted )
Ok, modules loaded: Main.

Now, run the application as:

*Main> main0
Loading package X11-1.2.1 ... linking ... done.
Loading package HGL-3.1.1 ... linking ... done.
*Main>

If everything is set up properly, this should show a GUI window with the text ‘HelloGraphicsWorld’ written on it. Pressing any key should dismiss this window.

About these ads
Categories: tech
  1. May 29, 2008 at 12:31 am

    This PC must be a very nice guy ;-)

    Birthday wishes once again mashe. Glad to see that you are already making good use of the book.

  2. July 21, 2008 at 3:58 am

    Hey, I read your post on the “FNU curse”, I needed to ask you something about it, and I’d rather do it over email. Hit me back if your ok with it — you have my email id now. :)

    Thanks.

  3. kristofer
    September 4, 2008 at 2:41 pm

    I’ve been trying to get around this x11 bug in gutsy.. I have no idea why, but your code works. I’ve been struggling to get this going for over a month. Thanks for the write-up.

  4. thanks
    November 26, 2008 at 7:43 pm

    Thanks for the “ignition”, it’s really valuable for beginners, like one am I.

  5. john
    January 24, 2010 at 2:19 pm

    hey,
    I followed the instructions you specified including both apt-get install’s and I’m still getting:

    Failed to load interface for `Graphics.SOE’

    I’m on Ubuntu 9.04
    Any ideas why? Thanks!

  6. john
    January 24, 2010 at 2:43 pm

    dude, so it doesn’t quite work with the install’s but here is the solution to the problem: http://www.haskell.org/soe/software1.htm

    cheers mate!

  7. Anukool
    January 7, 2011 at 6:30 am

    Thanks! I was trying to install soegtk and ubuntu was complaining and failing. I wouldn’t have known that SOE was a part of HGL without this post!

  8. hkh
    November 14, 2011 at 11:21 am

    OK, your instructions work. Thanks!

    But the text in the window does not appear until I mouse over the window. Why is that?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: