Haskell GUI


Friday, December 7th, 2007 at 6:56 pm, fp

In the last few days I’ve been checking out some haskell GUI frameworks. This is what I found so far.

Gtk2Hs

As the name says, Gtk2Hs is a library which bases on the Gtk+ project. It supports native look’n'feel and is supported on Linux, MacOS and Windows. You can even use the glade interface builder on Linux for creating your Haskell guis.

The user interface code is implemented in one big Monad (how else?) and a hello world application looks like

import Graphics.UI.Gtk
 
main :: IO ()
main = do
  initGUI
  window <- windowNew
  button <- buttonNew
  set window [ containerChild := button ]
  set button [ buttonLabel := "Hello World" ]
 
  onClicked button (putStrLn "Hello World")
  onDestroy window mainQuit
  widgetShowAll window
  mainGUI

wxHaskell

wxHaskell is a Haskell like wrapper built on top of the C++ wxWidgets framework. It runs on all major platforms as well and supports native look’n'feel. The MacOS port is available as a darcs repository.

The example.

module Main where
import Graphics.UI.WX
 
main :: IO ()
main = do
  f <- frame    [text := "Hello World"]
  quit <- button f [text := "Quit", on command := close f]
  set f [layout := widget quit]

HOC

On http://hoc.sourceforge.net/ there are Objective-C bindings so it is possible to access MacOS’ Cocoa library from Haskell and build Cocoa objects from Haskell.

[Update]

Eric pointed out some mistakes.

Tags: ,

6 Responses so far

  1. giu Says:

    very nice! tried gt2khs, easy to install, easy to execute, “easy” to code! I like the gt2khs-code more than the wxhaskell one: it’s easier to understand, but you have more to write :) it’s just a matter of taste!

  2. steve Says:

    Yep. I choosed gtk2hs in the end. I prefer it over the others like you do.

    Btw, there are also, I would call them experimental, frameworks like Fruit or Fudgets

  3. Eric Kow Says:

    Hi Steve,

    The wxhaskell darcs repository has had Unicode support for quite a while now. Also, we have worked out some installation issues which should make installation on MacOS X easier.

    darcs get http://darcs.haskell.org/wxhaskell

    Finally, we are in the process of preparing a new release candidate. Is there any chance you would be interested in testing it out? Anyway, I’m happy that you’re happy with your choice! :-)

  4. steve Says:

    Hi Eric

    Thanks for the information. I will move away from OS X soon and I do not have much time these days. Anyway, of course I can test it a bit. Give me an interrupt when the RC is ready.

    Have a nice day

  5. Eric Kow Says:

    Hi again, Steve,

    Mac and Windows binaries are now available for 0.10.3rc1. Linux ones should be following shortly (by the end of this weekend, we hope)

    http://sourceforge.net/project/showfiles.php?group_id=73133&package_id=73173&release_id=582361

  6. Jesus Says:

    Install wxHaskell in OSX is a snap but I can’t install gtk2hs in OSX with ghs 6.10, if you like haskell maybe you like this toy: http://www.plt-scheme.org.

Leave a Reply