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.
Categories: tech
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.
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.
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.
Thanks for the “ignition”, it’s really valuable for beginners, like one am I.
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!
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!
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!
OK, your instructions work. Thanks!
But the text in the window does not appear until I mouse over the window. Why is that?