[Add wxhaskell homepage files (main html, css only). Eric Kow **20070120221304 I took the liberty of running dos2unix on these. ] { adddir ./homepage addfile ./homepage/afp2003-results.html hunk ./homepage/afp2003-results.html 1 + + + + + + + +Turtle graphics results AFP-2003 + + + + + +
+

AFP 2003: turtle graphics.

+

This year, everyone had delivered a functioning turtle language. Special credit goes to +Christof Douma for the nicest embedding of the turtle language using monads: +

+
+do forward 100
+   right 90
+   forward 100
+   ...
+
+ +

Unfortunately, besides a good mark, there is no prize for the best embedding :-) +Although it was a close finish with the teenage ninja turtles, +this year's bag of M&M's for the best drawing goes to +Niels van der Velden and Mart Kolthof for their flower-power submission! They can pick +up their price at the office of Daan Leijen (B023). +

+ +
+ +

Flower power from Niels van der Velden and Mart Kolthof

+ +

The teenage ninja turtle of Guno Heitman en Niels Reyngoud

+ +

The parallel turtles of Ingmar Brouns, Peter Nagel

+ +

Christof's klavertje vier

+ +

Recursive flowers of Robert van Herk

+
+
+ + + addfile ./homepage/applications.html hunk ./homepage/applications.html 1 + + + + + + + +wxHaskell + + + + +
+ + + +
+

Application screenshots

+

At the moment, only small to medium sized programs have been written in wxHaskell and +this page shows some of them. If you know about an interesting wxHaskell +application, write us and it may be presented here too :-)

+
+ +
+

Dazzle. +Dazzle is a Bayesian belief network editor that is developed +by the Decision Support System group of Utrecht University. +Dazzle uses the Smile C++ library, developed by +the Decision Systems Laboratory of Pittsburgh University, to leverage +standard Bayesian belief network algorithms. The interface is highly specialized, featuring custom +controls for representing multi-dimensional statistical nodes. +

+

+Dazzle on Windows XP +
WindowsXP (Click on image to enlarge) +

+
+ +
+

ICFP Programming Contest 2003 & 2004 – the technology behind the winners. +[www-2003 +,www-2004]. +wxHaskell 0.7 was used in the ICFP 2004 programming contest +by team Dunkosmiloolump to create an "ant" +simulator – and they won the contest! An early version of wxHaskell has been used in the ICFP 2003 contest +by Team Dom +to create a graphical editor for solving the tracks. The entry is interesting as they created the interface in +a single day, and also used C code fragments to directly program the wxWidgets repaint handler.

+

+ + + + +
+ ICFP 2003 graphical track editor + ICFP 2004 ant simulator
Track editor (click on image to enlarge)Ant simulator (click on image to enlarge)
+

+
+ +
+

hsReversi [www-page]. +Lucas Torrećo, Emanoel Barreiros, Hilda Borborema, and Keldjan Alves have written a reversi game with wxHaskell. It is possible to play versus CPU or versus another human player. The window appearance can be changed at any time in game, using the "skins" feature. It is available in portugese only. +

+

+hsReversi - click to enlarge. +
WindowsXP (Click on image to enlarge) +

+
+ +
+

GeBoP [www-page]. +Maarten Löffler has written GeBoP, the General Board games Player. This application uses a generic game +engine to host 8 different games that can be played against the computer. A tree control is used to visualize +the state of the game engine, and an MDI interface is used to display several games simultaneously. Source is +available on the GeBoP website. +

+GeBob games - click to enlarge. +
WindowsXP (Click on image to enlarge) +

+
+ +
+

Proxima +[www-page]. +The Proxima generic structure editor is written by Martijn Schrage. +Proxima is part of an ongoing research project to combine both structured editing operations with free editing +(and if you look closely at the screenshot you can see that the variables in scope, the types, and even values +are automatically computed).

+

+ + + +
Proxima on MacOS XProxima on Windows XP
MacOS X (click on image to enlarge)Windows XP (click on image to enlarge)
+

+
+ +
+

A functional form +Functional Forms [www-page]. +Sander Evers has made a library for wxHaskell to concisely create forms: dialogs that display and +edit a set of values. All edit actions are automatically checked and converted to an appropiate Haskell form. +

+

 

+

 

+

 

+
+ +
+

HCPN [www-page]. +Claus Reinke has made an experimental graphical editor for +Haskell Coloured Petri Nets (HCPN).

+

+HCPN editor +
WindowsXP (Click on image to enlarge) +

+
+ +
+

HPView [www-page]. +Wei Tan has made a graphical heap profile viewer for GHC with wxHaskell, called HPView. It is intended as an interactive alternative to the hp2ps utility (included in GHC), which allows zooming and filtering of graph columns.

+

+HPView - click to enlarge. +
WindowsXP (Click on image to enlarge) +

+
+ + +
+

Haskell on the cover of a magazine! wxHaskell was featured in a two-page article in the october 2003 version of L'informaticien, a popular French PC magazine. The article has been written by Frédéric Mazué. Here are some screenshots:

+
+

+Page 1 +Page 2 +

+

+Cover

+
+
+ +
+toplast update: "Jun 5 2005". +
+
+ + + addfile ./homepage/assignment.html hunk ./homepage/assignment.html 1 + + + + + + + +Turtle graphics + + + + + +
+

AFP assignment: turtle graphics.

+

You are going to implement an embedded domain specific language to +describe turtle graphics. The goal of this assignment is to give you a +feel for the design issues involved with an embedded language and experience +with first-class IO values and graphical user interfaces.

+

The idea is that there is a turtle that carries a pencil that can draw on a +canvas. The turtle is knows just two primitive commands:

+
right d
+forward n
+

That is, it can go forward for n units, or it can +turn right over d degrees. For example, we can draw a +square using the following commands:

+ +
forward 50
+right 90
+forward 50
+right 90
+forward 50
+right 90
+forward 50
+ +

You can find more examples and information at the following webpage: http://el.www.media.mit.edu/groups/logo-foundation/logo/turtle.html + +

+ +

Prerequisites

+

It is encouraged to do this assignment with the wxHaskell 0.2 library +at http://wxhaskell.sourceforge.net. +Unfortunately, this means that you need ghc 6.01 and administrator rights.  +This implies that only people with access to a computer that they own, can do +this assignment with wxHaskell. I can probably provide a few people (up +to 4) with a dedicated computer in the ST-lab in the CGN building.  + +

+ +

If you really need to work on a standard lab machine, you can also do the +assignment using the SOE graphics library for Hugs: http://cvs.haskell.org/Hugs/pages/downloading.htm. +See their documentation about how to open windows and do drawing.  + +

+ +

Assignments

+

Assignment 1

+

Implement the turtle language as an embedded language in Haskell. The +language is embedded in Haskell as a single module that exports abstract data +types and associated operations. You should consider carefully what operations +you want to expose to the user so that programming with turtles becomes +convenient. For example, you could start with an interface like this:

+
data Drawing  
+
forward :: Double -> Drawing
+right   :: Double -> Drawing
+...
+

Of course, this is just an example and you can define another kind of +interface, as long as it has the same basic functionality. In both cases, you +need to be able to defend why you have chosen for a particular approach. Other +turtle commands you should implement are penup and pendown, +to either hide or show the trail of the turtle, color that changes +the color of the pen, and stop to end a +program.

+

Other commands are somewhat easier to add: backward, left, +and repeat. Why are these easier to add?

+

You should also provide an execute function that takes a turtle +program and runs it. Think about how general your function should be: should it +open its own window and take of everything itself, or should it be parameterised +by a window or drawing functions? Explain why you have chosen a particular +approach. Think also about a coordinate system: do you use pixels as units? what +happens on a resize of the window?  Note that your turtle should start in +the center, going upwards.

+

You implementation doesn't have to show a turtle: it just has to show how the +final result looks like. Check your implementation by implementing the spiral +example from the http://el.www.media.mit.edu/groups/logo-foundation/logo/turtle.html + + webpage.

+
to spiral :size :angle 
+  if :size > 100 [stop] 
+  forward :size 
+  right :angle 
+  spiral :size + 2 :angle 
+end
+

Of course, you would implement your examples in a separate module than the Turtle +module.

+

Assignment 1a (optional)

+

Instead of drawing the result of a turtle drawing, show how the drawing is +drawn. You don't have to show a turtle itself, just showing the effect of the +turtle moving around is good enough. You could use a timer together +with a mutable variable and repaint to animate the drawing. Look at +the wxHaskell bouncing balls example for an illustration of their usage. +If you use SOE graphics, you can probably use sleep (or Win32.sleep) +to achieve the same effect.

+

Once this works, you can also try to implement the forever +operator.

+

Assignment 2

+

Implement parallel composition to your interface. One possible interface +could be:

+
(<|>) :: Drawing -> Drawing -> Drawing
+

When you execute the drawing p <|> q there will be two +turtles, one drawing p, the other drawing q in parallel.

+ +

Think about what happens after a parallel composition finishes? Is the +operator commutative? and associative? Why would these laws be important to a +programmer?

+ +

Assignment 3

+ +Several other extensions to the simple turtle language can be made. Implement at +least one extension from this list:

1. You could add a save construct to the language. +

  save :: Program -> Program
+
+The meaning of the program save p is to recall the current position of +the turtle and to continue with the program as if nothing happened. But as soon +as we are done, we return to the saved state and execute the program p +from that point. When you have several save statements in your program, +all of them should be saved and later executed, but you may decide yourself in +what order. +

2. You could add a pause construct to your language. In this +case, you will add a button with the text "Continue" to the graphical +interface. This button is normally inactive, but when the turtle program +executes the pause command, it halts, and the "Continue" button +becomes active. When the user clicks on the "Continue" button, the +program continues and the continue button becomes inactive again. +

3. Similar to 2., but instead of an explicit pause, you have a +combinator called stepping. +

  stepping :: Program -> Program
+
+The meaning of the program stepping p is: execute p as normal, but +the user is required to click the "Continue" button at every step +during the execution of p. +

4. Add the commands showturtle and hideturtle to your +language, which toggle between having a turtle picture shown when drawing the +pictures or not. A variant of this allows different turtle bitmaps and maybe +even a background image. One can then describe simple animations. Also see the +section "Up and Away" from the above mentioned turtle web page. +

5. Add a way to your language of finding out information about for +example, where the turtle currently is, or if the user clicks or drags the mouse. It +should of course be possible to then use this information in your turtle +programs. +

6. Invent your own extension to the turtle language. By extension I +mean something that cannot be implemented in terms of the existing language +constructs.

+

Assignment 4

+ +

Create a cool picture that uses some or all the extensions that you have +made. To keep up a long standing tradition, the team with the best demo, +subjectively chosen by me :-), wins a bag of M&M's.

+ +

Assignment 5

+ +

Answer and motivate the following questions:

+
    +
  1. Compare the usability of your embedding against a custom-made + implementation of a turtle language with dedicated syntax and interpreters. + How easy is it to write programs in your embedded language compared to a + dedicated language? What are the advantages and disadvantages of an + embedding?
  2. +
  3. Compare the ease of implementation of your embedding against a custom-made + implementation. How easy was it to implement the language and extensions in + your embedded language compared to a dedicated language? What are the + advantages/disadvantages of an embedding?
  4. +
  5. In what way have you used the following programming language features: + higher-order functions, laziness, and polymorphism?
  6. +
+

Submission

+

You should send your submission before Sunday, 28 September, 23:59h to +daan@cs.uu.nl with the subject afp submission. In the body, you should  put the names of your team and +the student numbers. You should attach the following (zipped/tarred) files:

+
    +
  1. A module Turtle.hs that contains your embedding of the turtle + language.
  2. +
  3. A module Main.hs that contains your examples. If I run main, + I should see the coolest example you have made.
  4. +
  5. A text file named report that contains the answers to the + questions and comments and motivations about your implementation.
  6. +
+Your code will also be judged on elegance! +

Success! +

+ + + addfile ./homepage/building-cygwin.html hunk ./homepage/building-cygwin.html 1 + + + + + + + + +wxHaskell - Building - Cygwin installation + + + +
+ + + + + +
+

Unix on Windows

+

To build wxHaskell on windows, you need the cygwin environment to provide essential unix +tools necessary to run configure and make, i.e. sh, test, sed, gnu make etc. The cygwin environment provides these tools +on windows and these notes describe how to properly install these tools. To compile wxWidgets properly +without using Microsoft Visual C++, you also need to install the mingw compiler, as described in the +section after installing cygwin. Please note that the compilation of wxWidgets also works without +the mingw compiler, but all programs linked with it will fail mysteriously! +

+
+ +
+

Install Cygwin

+

Download the setup program from the cygwin site. When +prompted for the packages to install, click also on the Devel and Archive +node until they show install (instead of default).

+ +

After installation, you need to set a few environment variables. In the following description you +should replace the variable $cygwin with your cygwin +installation directory (c:\cygwin by default). Set your local environment variables +(via start/settings/control panel/system/advanced/environment variables) to the +following values:

+
    +
  • Add the following directories to your PATH: $cygwin\bin and +$cygwin\usr\local\lib. On my +system this looks like: +
    +PATH = %PATH%;c:\programs\cygwin\bin;c:\programs\cygwin\usr\local\lib;...
    +
    +
  • +
  • Set SHELL to $cygwin\bin\sh.
  • +
  • Set MAKE_MODE to UNIX.
  • +
  • Set HOME to your preferred home directory, for example: c:\bgates.
  • +
+ +

Next, we need to ensure that the default shell is bash. Go to the $cygwin/bin +directory and rename sh.exe to sh-org.exe. Next, make a copy of bash.exe +and name it sh.exe.

+ +

We also set some default settings for bash. Create a file .bashrc in your +home directory with the following lines:

+
+export CVS_RSH=ssh
+export PS1='\[\033[1;31m\]\w\$ \[\033[0m\]'
+export PATH=$PATH:/usr/local/bin:.
+
+ +

Finally, you can start a bash command prompt, either via the cygwin icon or by typing +bash on the windows command line. To access the c: drive conveniently +from the bash command prompt, you can mount the /c directory. You only have to +do this once:

+
+> mount c: /c
+
+ +

From now on, you can access the c: drive via /c, for example: cd /c/windows

+
+ +
+

Installing Mingw

+

In order to compile dynamic link libraries that should work with GHC, we also need the minimalist +gnu compiler, called mingw. Compiling with this compiler has the extra advantage that the +resulting executables or no longer dependent on the cygwin dll.

+ +

Download the latest compiler from the mingw site. There +are a lot of packages available but you only need the +MinGW package. +

+ +

After installation, you still need to adapt the cygwin environment in order to use the +mingw compiler by default. In the following description, you should replace the $mingw +variable with the mingw installation directory (c:\mingw by default).

+
    +
  • Add the $mingw/bin directory to the start of your PATH environment +variable. It is important that it comes before the $cygwin/bin directory. On my +system this looks like: +
    +PATH = %PATH%;c:\programs\mingw\bin;c:\programs\cygwin\bin;...
    +
    +
  • +
  • Edit the file $cygwin/etc/profile and add the $mingw/bin directory +to the exported PATH. You should use a unix style directory name. On my system +this looks like: +
    +export PATH="/c/programs/mingw/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
    +
    +
  • +
+ +

To see if your installation was succesfull, you should retrieve the version +of the C compiler and see if the result contains the word mingw:

+
+~$gcc --version
+gcc.exe (GCC) 3.2 (mingw special 20020817-1)
+Copyright (C) 2002 Free Software Foundation, Inc.
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ +

In constrast, if you have done something wrong, you would see something like:

+
+~$/c/programs/cygwin/bin/gcc --version
+gcc (GCC) 3.2 20020927 (prerelease)
+Copyright (C) 2002 Free Software Foundation, Inc.
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/building-macosx.html hunk ./homepage/building-macosx.html 1 + + + + + + + + +wxHaskell - Building - MacOS X + + + +
+ + + + + +
+ +

Using wxHaskell on MacOS X platforms

+

Even though graphical applications on MacOS X look great, it is a still +a developers nightmare to get them working :-). Furthermore, the MacOS X port of wxWidgets +is the least mature and still has some quirks. This page describes how to circumvent some of the pitfalls.

+ +
    +
  • Haskell applications need the readline library which is not installed by +default on the MacOS X. Arthur Baars provided +a simple installer for the readline library.

    + +
  • +

    Graphical applications generated with GHC do not work if executed directly – they need to be +upgraded into MacOS X applications. The macosx-app script does this for you. It +is provided with binary releases and resides in the bin directory of +a source release. Creating a program now consists of the following steps:

    +
    +> cd samples/wx
    +> ghc -package wx -o helloworld HelloWorld.hs
    +> /usr/local/wxhaskell/bin/macosx-app -v helloworld
    +> open helloworld
    +
    +
  • + +
  • +

    Due to complicated MacOS X restrictions, graphical wxHaskell applications do not work directly +when used from GHCi. Fortunately, Wolfgang Thaller has kindly provided an ingenious +Haskell +module that solves this problem. Just import the (compiled) module EnableGUI +in your program and issue the following command to run main from your GHCi prompt:

    +
    +> enableGUI >> main
    +
    +
  • + +
  • The dynamic link libraries used by wxHaskell can not always be found. If your +application seems to start (the icon bounces) but terminates mysteriously, you need +to set the dynamic link library search path to the wxHaskell library directory. For example:

    +
    +> setenv DYLD_LIBRARY_PATH /usr/local/wxhaskell/lib
    +
    +
  • +
+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/building-msc.html hunk ./homepage/building-msc.html 1 + + + + + + + + +wxHaskell - Building - Visual C++ + + + +
+ + + + + +
+

Building wxWidgets and wxc with Microsoft Visual C++

+ +

The advantage of using Visual C++ is that the resulting libraries are smaller and faster +than the gnu compiled ones. Furthermore, the debug version provides for automatic detection +of memory leaks in the wxWidgets libraries and you get a warning when forgetting to deallocate +wxWidgets objects. The drawback is that the configure scripts are not used and you will need +to set some options manually.

+ +

We use the wxWidgets provided workspace directly:

+
    +
  • wxWidgets 2.4: Open the $wxwin/src/wxWidgets.dsw workspace. +Select menu "Build/Set active configuration" and select "wxWidgets - win32 release" to build the (static) library. After compilation, you can also select "wxWidgets - win32 debug" to build +the debug version.
  • +
  • wxWidgets 2.5: Open the $wxwin/build/msw/wx.dsw workspace. Select +menu "Build/Batch build" and select all configurations by using the mouse and the shift key, +when you click a marker, all configurations are deselected. Next you manually select the "Release" and "Debug" versions of all projects and press "Build". Afterwards, press "Save All" to save all your mouse clicking work :-)
  • +
+ +

After building wxWidgets, you need to run configure for the wxHaskell library.

+
+> cd $wxhaskell
+> ./configure --with-msc
+
+ +

If you want to use the debug version of the library, use the --wxc-libname option too.

+
+> ./configure --with-msc --wxc-libname=wxcd
+
+ +

After configuration, first go the $wxhaskell/wxc directory. Here, you need to adapt the wxc-version.dsp project to reference the correct wxWidgets directory. Open the .dsp file in an editor and replace all occurrences of "..\..\wxWindows-2.4.2" (or "..\..\wxWindows-2.5.1") or by the installed wxWidgets directory, i.e. $wxwin. +

+ +

After adapting the project file, you can open the workspace wxc/wxc-version.dsw +and build the release and debug versions of the C wrapper library.

+ +

And finally! – you can run make in the $wxhaskell directory to build the +Haskell libraries.

+
+> cd $wxhaskell
+> make
+> make install
+
+ +
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/building.html hunk ./homepage/building.html 1 + + + + + + + +wxHaskell - Building + + + + +
+ + + + + + +
+

Building from sources

+

In principle we recommend the use of binary releases, but +wxHaskell also has a build system to compile directly from sources. The build process has +been specialized for three main platforms:

+
    +
  • unix-gtk. General unix systems with GTK.
  • +
  • macosx. Mac OS X.
  • +
  • windows. General windows systems (i.e. win95 to winXP). We support both building with + the Microsoft Visual C++ compiler version 6 and 7 (windows-msc) and building with the + gnu mingw32 C compiler (windows-mingw).
  • +
+ +

wxHaskell has been build successfully on (at least) the following configurations:

+
    +
  • windows. Windows 98, windows 2000, and windowsXP, using wxMSW 2.4.x, 2.5.x, and 2.6.x.
  • +
  • macosx. Mac OS X 10.2 (Jaguar) and 10.3 (Panther) with ghc 6.2.x and wxMAC 2.4.2 and 2.5.x.
  • +
  • unix-gtk. Red Hat Linux 10 (Fedora), FreeBSD, and Gentoo Linux, using wxGTK 2.4.2, 2.5.x, and 2.6.x.
  • +
+ +

(Unfortunately, there are still build problems on Sun Solaris – we are looking for build volunteers :-)

+
+ +
+

Prerequisites

+ +

Ensure you have a recent GHC compiler – version 6.4 is recommended (but any version >= 5.04.3 will work). In principle, any Haskell98 compiler that supports the standard FFI libraries will also work.

+ +
    +
  • windows: you need the cygwin environment together +with the mingw compiler. The build process is very sensitive to the +cygwin setup and there is a separate guide for installing cygwin properly. +
  • + +
  • macosx: you need to install the gcc compiler, which is part of the Apple +Developer Tools. These tools are shipped with Panther and are installed by invoking Applications/Installers/Developer Tools/Developer.mdmg. +
  • + +
  • ghci: the GHCi interpreter only works with wxWidgets version 2.4.2 on Windows platforms. +
  • +
+ + +

Next, you should install the latest stable version (currently 2.6.0) of wxWidgets +for your platform. We assume in this guide that the variable $wxwin points to your +wxWidgets installation directory, for example: ~/dev/wxGTK-2.6.0.

+ +
    +
  • windows: ghci only works with wxWidgets 2.4.2. Since this wxWidgets version is very stable, it is recommended on windows platforms. +
  • + +
  • macosx: MacOS X works best with wxWidgets 2.5.4. The latest stable release (currently wxMAC-2.6.0) does not display menus properly. +
  • +
+ + +

If you have a source release of wxHaskell, +just unpack it in a suitable directory. In the +following descriptions, we assume that the variable $wxhaskell points to your +installation directory, for example: ~/dev/wxhaskell. +

+ +

If you do not have a source release of wxHaskell, you need to check it out from the cvs repository. CVS creates a +wxhaskell directory for you; we assume in the following example that +your $wxhaskell directory will be ~/dev/wxhaskell.

+
+> cd ~/dev
+> cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/wxhaskell login
+> cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/wxhaskell co -P wxhaskell
+
+ +

You can check out a specific release version using the -r flag:

+
+> cvs -z3 -d:<as above> co -P -r wxhaskell-0-4 wxhaskell
+
+ +

You might need to try a few times as sourceforge has a limit on the +number of people that can log in anonymously.

+
+ +
+

Building wxWidgets

+

windows-msc: this section describes how to build wxWidgets +using standard gnu tools -- there is a separate section on +building the library with Microsoft Visual C++ on windows.

+ +

According to the wxWidgets preferred installation, create a mybuild directory in the +wxWidgets directory, and run configure and make from that directory (and take the time to get some coffee :-). +

+
> cd $wxwin
+> mkdir mybuild
+> cd mybuild
+> ../configure --disable-shared
+> make
+> make install
+
+ +Notes: +
    +
  • Add the following flags to configure, to enable certain advanced features of wxHaskell: +
    • --disable-shared to build a static library (recommended for wxHaskell version >= 0.7).
    • +
    • --with-odbc to enable database access.
    • +
    • --with-opengl to enable the openGL canvas.
    • +
    • --enable-sound to enable playback of wave audio files. (--enable-wave on + wxWidgets 2.4.x)
    • +
    +
  • +
  • Do not forget to run make install; this installs a utility called +wx-config that is used by the other projects.
  • +
  • unix-gtk: if you want to use the GTK-2 toolkit, you need to configure without +unicode support since wxHaskell can not (yet) handle unicode. Try for example: +
    +../configure --with-gtk --enable-gtk2 --disable-unicode
    +
  • +
  • macosx: you might need to run rehash after make install +in order to add the wx-config utility to the search path cache.
  • +
  • windows: sometimes the header file $wxwin\include\wx\msw\popupwin.h +is not properly copied when make install is run, and you need to +copy it manually to the install directory (for example /usr/local/include/wx/msw). +(if this file is not copied, C compilation of wxHaskell will fail). +
  • +
+ +

Now try out a few samples of wxWidgets to see if it all works correctly:

+
+> cd samples/controls
+> make
+> ./controls
+
+ +

Note that you build from the local samples directory that resides +in the mybuild directory.

+ +

And also try if wx-config works too:

+
+> wx-config --version
+
+
+ +
+

Building wxHaskell

+ +

First, we configure the library for your platform.

+ +
+> cd $wxhaskell
+> ./configure
+
+ +Notes: +
    +
  • You can run configure first with the --help option. This also shows the values of command-line options and is an excellent check to see +if everything is set up correctly. If the settings do not make sense, it might be that the wx-config +utility is not found – maybe you have forgotten to run make install on wxWindows?
  • +
  • You should pass the --with-opengl option to configure if you specified this +flag when configuring wxWidgets (or you will get link errors).
  • +
  • By default, the library is installed in the wxWidgets install directory. You can specify another directory with the +prefix option of configure: ./configure --prefix=/usr/local. Any directory that is on your library search path will do.
  • +
  • windows-msc. Read the notes on building wxHaskell with Visual C++.
  • +
  • ghc 6.0.1, wxhaskell 0.8: In the file wxcore/src/Graphics/UI/WXCore/WxcObjects.hs you need to switch the parameters to newForeignPtr on line 172. In the file wx/src/Graphics/UI/WX/Controls.hs you need to replace the import of Data.Typeable by Data.Dynamic.
  • +
+ +

After configuration, we build and install the libraries (and take some more time to drink more coffee :-).

+
+> make
+> make install
+
+ +Notes: +
    +
  • If make install fails when building the ghc package, you might not have administrator priviliges. Either run it as an administrator or configure in such a way that you use a local ghc package: +
    +./configure --package-conf=~/mypackages
    +
  • +
  • You can generate documentation with make doc. +
  • +
  • The libraries can be uninstalled with make uninstall. +
  • +
+
+ +
+

Test wxHaskell

+

If everything succeeded, you should be able to run a test program.

+
+> cd samples/wx
+> ghc -package wx -o helloworld HelloWorld.hs
+> ./helloworld
+
+ +

Notes:

+
    +
  • macosx: Unfortunately, wxHaskell programs do not work directly as generated by +GHC. Look at the MacOS X notes for more information.
  • + +
+ +

You can also run the examples from GHCi – a great development environment!

+
+> ghci -package wx BouncingBalls.hs
+> main
+
+ +

Notes:

+
    +
  • wxHaskell programs are not always properly reïnitialized when started +the second time from a GHCi prompt. This is due static variables in the wxWidgets C++ code, and +we are working with wxWidgets developers to remove those bugs. Currently, GHCi only works well +with wxWidgets 2.4.2. +
  • gtk: Unfortunately, one can only start a wxWidgets program once with GHCi on GTK (rendering it +useless).
  • +
  • macosx. You need to use a special command to run wxHaskell applications, see the +Mac OS X notes from more information.
  • + +
+ +

Have fun!
+   -- Daan Leijen.

+
+ +
+toplast update: "May 8 2005". +
+ +
+ + addfile ./homepage/contribute.html hunk ./homepage/contribute.html 1 + + + + + + + +wxHaskell - Contribute to the project! + + + + +
+ + + + +
+

Contribute to wxHaskell!

+

"Do not ask yourself what wxHaskell can do for you, but what you can do for wxHaskell" :-)

+

However, it is hard to find out which features are particularly interesting, the +hardness of certain tasks, and whether you are duplicating work done by others. +This page tries to remedy this situation by giving a list of good starting points for +contributing to wxHaskell. +

+

If you feel like doing one of these items, please notify the maintainer of wxHaskell, or +send an e-mail to the wxHaskell mailing list, so that no effort is accidently duplicated. +

+
+
+

+ +
+ +
+

There are more desirable features that are planned for upcoming releases. However +most of these are somewhat harder to do as they require more knowledge about the +entire wxHaskell project. However, if you feel that you really need one of these +items, feel free to try! +

    +
  • Drag and drop.
  • +
  • Clipboard, copy and past.
  • +
  • Grid control support.
  • +
  • Better internet support.
  • +
  • ...
  • +
+

+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/dev-download.html hunk ./homepage/dev-download.html 1 + + + + + + + +wxHaskell - Development Download + + + + +
+ + + + +
+

Download

+

There are no development releases yet. All the sources are only available +through the cvs repository. +

+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/development.html hunk ./homepage/development.html 1 + + + + + + + +wxHaskell - Development + + + + +
+ + + + +
+

Development

+

wxHaskell is an open-source project, and you are invited to help developing wxHaskell! (see the +contribute page for more information.) Currently +the development team consists of:

+
+
Daan Leijen
+
The main developer and designer of wxHaskell
+
+ +

Furthermore, the following people have contributed to the wxHaskell project:

+
+
Wolfgang Thaller
+
Contributed a nifty MacOS X module that enables the use of GHCi on MacOS X.
+
Martijn Schrage
+
Helped to design the library interface and tested the library by using wxHaskell +as a backend to Proxima – a sophisticated generic structure editor.
+
Arjan van IJzendoorn
+
Developer of NetEdit and provides a lot +feedback for improving the library.
+
Maarten Loffler, Sean Seefried, and Luc Taesch
+
Contributed samples to the library. Maarten also helped creating a proper windows98 +installer.
+
Andres Löh
+
Testing on Gentoo Linux with GTK (and has written the graphical editor +used by team DOM in the ICFP contest).
+
Arthur Baars
+
Testing on MacOS X, and creating MacOS X installers.
+
Wijnand Suijlen
+
Has written the Helium interpreter in wxHaskell and initiated the design of the +layout combinators.
+
Eelco Dolstra and Armijn Hemel
+
Kindly provided their linux computers and unix wisdom :-) to test wxHaskell on +Linux/GTK systems. Special thanks goes to Armijn Hemel for maintaining a Red Hat Linux +and MacOS X system for testing in the student laboratories.
+
Jens Petersen
+
Created the initial rpm specification files and released a few rpm distributions of wxHaskell
+
+
+ +
+

Overview

+

wxHaskell is a project hosted on sourceforge. The sources are +available on the sourceforge cvs repository. +Currently, wxHaskell hosts four subprojects. +

+
    +
  • wx [documentation]. The main middle-level library. This library is written in Haskell and only depends on the wxcore package. It uses overloading and attributes to expose a nice functional +interface to the wxcore library. However, it does not try to create a new model +for programming GUI interfaces: everything is still in the IO monad and state is handled through mutable +variables.
  • +
  • wxcore [documentation]. The Haskell binding to the core wxWidgets library. This is just like programming the wxWidgets library directly, you can see some + examples + in the cvs. All the method definitions and marshaling code is generated automatically -- about 500 classes with 2500 methods and 1000 constant definitions. +wxcore uses the following two sub-projects: +
      +
    • wxc. A C project that puts a C wrapper around the C++ interface to wxWidgets. This makes it +much easier to access the wxWidgets library from Haskell. The C wrapper consists of the C sources of the Eiffel ewxw library for wxWidgets. We also added a few files to make the project suitable for Haskell, but we made no changes to the original Eiffel sources. This way, we are able to automatically update the sources from their cvs server. A big thank-you to the people that worked on the Eiffel library! +
    • wxdirect. A Haskell program that reads the C header files of the Eiffel wxWidgets C library and automatically generates Haskell marshaling code and class definitions. +
    +
  • +
+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/documentation.html hunk ./homepage/documentation.html 1 + + + + + + + +wxHaskell - Documentation + + + + +
+ + + + +
+

Documentation

+

(All of the following links are cheap to follow)

+ +
+ +
+toplast update: "May 3 2005". +
+ +
+ + addfile ./homepage/download.html hunk ./homepage/download.html 1 + + + + + + + +wxHaskell - Download + + + + +
+ + + + +
+

Download

+

You can download either a source or binary distribution. The +documentation and samples are normally included in binary distributions. After installation, you should try some of the +samples to see if everything works as expected:

+
+> cd samples/wx
+> ghc -package wx -o helloworld HelloWorld.hs
+> ./helloworld
+
+ +

You can also use GHCi – a great development environment for GUI's! (Unfortunately, GHCi only works well on Windows platforms at the moment)

+
+> ghci -package wx HelloWorld.hs
+*Main> main
+
+ +

See the documentation for more information about wxHaskell.

+
+ +
+

Version 0.9.4 – May 3, 2005   (updated May 8, 2005)

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.9.4-1.zip (updated)
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.9.4.zip
+
Documentation and samples.
+
+ +

Binary packages

+ +

The file name of a binary release contains the version of the wxWidgets toolkit that has been used, +and the version of the Haskell compiler was used to build wxHaskell. Make sure that +you have the same version of the compiler installed, for example ghc6.4. All packages have ODBC and OpenGL support. Documentation and samples are not included with Linux rpm packages.

+ +
+
wxhaskell-bin-msw2.4.2-ghc6.4-0.9.4-1.zip (Windows, ghc 6.4, updated)
+wxhaskell-bin-msw2.4.2-ghc6.2.2-0.9.4-0.zip (Windows, ghc 6.2.2) +
+ +
Unzip the release somewhere and click on the newly created wxhaskell-0.9.4\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.9.4\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.9.4 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ +
wxhaskell-gtk2.6.0-ghc6.4-0.9.4-0.i386.rpm (Linux, ghc 6.4)
+wxhaskell-gtk2.5.2-ghc6.2.2-0.9-0.i386.rpm (Linux, ghc 6.2.2)
+
Linux rpm built on Fedora. You need to be root to install the rpm. +
+ +
wxhaskell-bin-mac2.5.4-ghc6.4-0.9.4-0.dmg (MacOS X, ghc 6.4)
+wxhaskell-bin-mac2.5.4-ghc6.2.2-0.9-0.dmg (MacOS X, ghc 6.2.2)
+
The installer copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with ghc. To test the installation, +you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> open hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

+
+
+ +
+

Version 0.9 – Feb 25, 2005

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.9.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.9.zip
+
Documentation and samples.
+
+ +

Binary packages

+ +

The file name of a binary release contains the version of the wxWidgets toolkit that has been used, +and the version of the Haskell compiler was used to build wxHaskell. Make sure that +you have the same version of the compiler installed, for example ghc6.2.2. All packages have ODBC and OpenGL support. Documentation and samples are not included with Linux rpm packages.

+ +
+
wxhaskell-bin-msw2.4.2-ghc6.2.2-0.9-0.zip (windows, ghc 6.2.2)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.9\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.9\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.9 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ +
wxhaskell-gtk2.5.2-ghc6.2.2-0.9-0.i386.rpm (linux, ghc 6.2.2, wxWidgets 2.5.2 (development snapshot))
+
Linux rpm built on Fedora Core 1 (Red Hat Linux). You need to be root to install the rpm. +
+ +
wxhaskell-bin-mac2.5.4-ghc6.2.2-0.9-0.dmg (MacOS X, ghc 6.2.2, wxWidgets 2.5.4 (development snapshot))
+
The installer copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with ghc. To test the installation, +you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> open hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

+
+
+ +
+

Version 0.8 – Jul 27, 2004

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.8.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.8.zip
+
Documentation and samples.
+
+ +

Binary packages

+ +

The file name of a binary release contains the version of the wxWidgets toolkit that has been used, +and the version of the Haskell compiler was used to build wxHaskell. Make sure that +you have the same version of the compiler installed, for example ghc6.2.1. All packages +have ODBC and OpenGL support. Documentation and samples are not included with Linux rpm packages.

+ +
+
wxhaskell-bin-msw2.4.2-ghc6.2.1-0.8-0.zip (windows, ghc 6.2.1)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.8\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.8\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.8 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ +
wxhaskell-gtk2.4.2-ghc6.2.1-0.8-0.i386.rpm (linux, ghc 6.2.1, wxWidgets 2.4.2 (stable))
+wxhaskell-gtk2.5.2-ghc6.2.1-0.8-0.i386.rpm (linux, ghc 6.2.1, wxWidgets 2.5.2 (development snapshot))
+
Linux rpm built on Fedora Core 1 (Red Hat Linux). You need to be root to install the rpm. +
+ +
wxhaskell-bin-mac2.5.2-ghc6.2.1-0.8-0.dmg (MacOS X, ghc 6.2.1)
+
The installer copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with ghc. To test the installation, +you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> open hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

Note: The installer for MacOS X has been build using a developer release of wxWidgets.

+
+
+
+ + +
+

Version 0.7 – Apr 2, 2004

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.7.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.7.zip
+
Documentation and samples.
+
+ +

Binary packages

+ +

The file name of a binary release contains the version of the wxWidgets toolkit that has been used, +and the version of the haskell compiler was used to build wxHaskell. Make sure that +you have the same version of the compiler installed, for example ghc6.2.1. All packages +have ODBC and OpenGL support. Documentation and samples are not included with Linux rpm packages.

+ +
+
wxhaskell-bin-msw2.4.2-ghc6.2.1-0.7-0.zip (windows, ghc 6.2.1)
+wxhaskell-bin-msw2.4.2-ghc6.2-0.7-0.zip (windows, ghc 6.2)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.7\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.7\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.7 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ + +
wxhaskell-gtk2.4.2-ghc6.2.1-0.7-0.i386.rpm (Linux, ghc 6.2.1)
+wxhaskell-gtk2.4.2-ghc6.2-0.7-0.i386.rpm (Linux, ghc 6.2)
+
An rpm built on Fedora Core 1 (Red Hat Linux). You need to be root to install the rpm. +Jens Petersen kindly provided the initial rpm specification files. +
+ +
wxhaskell-bin-mac2.5.1-ghc6.2.1-0.7-0.dmg (MacOS X, ghc 6.2.1)
+wxhaskell-bin-mac2.5.1-ghc6.2-0.7-0.dmg (MacOS X, ghc 6.2)
+
The installer copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with ghc. To test the installation, +you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> open hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

Note: The installer for MacOS X has been build using a developer version of wxWidgets and might be unstable (for example, applications are required to have a menu bar).

+
+
+
+ +
+

Version 0.6 – February 23, 2004

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.6.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.6.zip
+
Documentation and samples.
+
+ + +

Binary packages

+ +

The file name of a binary release contains the version of the haskell compiler that you need. Make sure that +you have the same version of the compiler installed, for example ghc6.2. Documentation and samples are +included.

+ +
+
wxhaskell-bin-msw-ghc6.2-0.6-1.zip (windows, ghc 6.2) (updated on Feb 29 2004)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.6\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.6\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.6 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ +
(MacOS X, ghc 6.2)
+
Not yet available. Here is the MacOS X situation as of Feb 23 2004: +
    +
  • MacOS X, 10.2 (Jaguar): Builds fine and generates installers but we no access anymore to such machine +(and thus, we can not build an installer).
  • +
  • MacOS X, 10.3 (Panther): wxWidgets 2.4.2 fails to build on this system. wxHaskell builds fine with the +latest CVS snapshots of wxWidgets (2.5.1, Feb 20 2004), but these versions contain menu bugs.
  • +
+

See below for an MacOS X installer for wxHaskell version 0.4.

+
+ +
(Red Hat Linux RPM, ghc 6.2)
+
Not yet available. However, this version has been build and tested on Fedora (Red hat 10) and +free-bsd without problems. See below for an rpm for wxHaskell version 0.2. +
+
+
+ +
+

Version 0.5 – February 12, 2004

+

Package patched on February 19, 2004

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-src-0.5-1.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
wxhaskell-doc-0.5.zip
+
Documentation and samples.
+
+ + +

Binary packages

+ +

The file name of a binary release contains the version of the haskell compiler that you need. Make sure that +you have the same version and compiler installed, for example ghc6.2. Documentation and samples are +included.

+ +
+
wxhaskell-bin-msw-ghc6.2-0.5-1.zip (Windows, ghc 6.2)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.5\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.5\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.5 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-unregister.bat. +

+
+ +
(MacOS X, ghc 6.2)
+
Not yet available. See below for an installer for wxHaskell version 0.4. +
+ +
(Red Hat Linux RPM, ghc 6.2)
+
Not yet available. See below for an rpm for wxHaskell version 0.2. +
+
+
+ +
+

Version 0.4 – November 7, 2003

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-doc-0.4.zip
+
Documentation and samples.
+
wxhaskell-src-0.4.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
+ + +

Binary packages

+ +

The file name of a binary release contains the version of the haskell compiler that you need. Make sure that +you have the same version and compiler installed, for example ghc6.0.1. You need to download the documentation and samples separately.

+ +
+
wxhaskell-bin-msw-ghc6.0.1-0.4.zip (Windows, ghc 6.0.1)
+
Unzip the release somewhere and click on the newly created wxhaskell-0.4\bin\wxhaskell-register.bat program to register the wxHaskell package. To uninstall, you can click on wxhaskell-0.4\bin\wxhaskell-unregister.bat and than remove the wxhaskell-0.4 directory. + +

Note:If you have an older version of wxHaskell installed, please remove it before installing this version. +Older releases can be uninstalled by clicking on wxhaskell-uninstall.bat in the ghc directory. +

+
+ +
wxhaskell-bin-mac-ghc6.0.1-0.4.dmg (MacOS X, ghc 6.0.1)
+
An installer for MacOS X. It copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with GHC. +To test the installation, you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> ./hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

+
(Red Hat Linux RPM, ghc 6.0.1)
+
Not yet available. See below for an rpm for version 0.2. +
+
+
+ + +
+

Version 0.3 – October 1, 2003

+

All of these files are also directly available from the +sourceforge project page.

+ +

Basic packages

+
+
wxhaskell-doc-0.3.zip
+
Documentation and samples.
+
wxhaskell-src-0.3.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
+ + +

Binary packages

+ +

The file name of a binary release contains the version of the haskell compiler that you need. Make sure that +you have the same version and compiler installed, for example ghc6.0.1. You need to download the documentation and samples separately. Binary releases can be installed right over older releases.

+ +
+
wxhaskell-bin-msw-ghc6.0.1-0.3.zip (Windows, ghc 6.0.1)
+
Unzip the release on top of the ghc install directory, for example c:\ghc\ghc-6.0.1. +After unzipping, click on the newly created wxhaskell-register.bat program to register +the wxHaskell package. To uninstall, you can click on wxhaskell-uninstall.bat. +
+ +
wxhaskell-bin-mac-ghc6.0.1-0.3.dmg (MacOS X, ghc 6.0.1)
+
An installer for MacOS X. It copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with GHC. +To test the installation, you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> ./hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

+
(Red Hat Linux RPM, ghc 6.0.1)
+
Not yet available. See below for an rpm for version 0.2. +
+
+
+ + +
+

Version 0.2 – 16 September 2003

+

All of these files are also directly available from the +sourceforge project page.

+

Note: unfortunately, the +FileBrowse example +has accidentally not been included in the release.. but it easy to download it yourself from +cvs.

+ +

Basic packages

+
+
wxhaskell-doc-0.2.zip
+
Documentation and samples.
+
wxhaskell-src-0.2.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
+ + +

Binary packages

+ +

The file name of a binary release contains the version of the haskell compiler that you need. Make sure that +you have the same version and compiler installed, for example ghc6.0.1. You need to download the documentation and samples separately. Binary releases can be installed right over older releases.

+ +
+
wxhaskell-bin-msw-ghc6.0.1-0.2.zip (Windows, ghc 6.0.1)
+
Unzip the release on top of the ghc install directory, for example c:\ghc\ghc-6.0.1. +After unzipping, click on the newly created wxhaskell-register.bat program to register +the wxHaskell package. To uninstall, you can click on wxhaskell-uninstall.bat. +
+ +
wxhaskell-bin-mac-ghc6.0-0.2.dmg (MacOS X, ghc 6.0)
+
An installer for MacOS X. It copies the wxHaskell libraries to +/usr/local/wxhaskell and registers them with GHC. +To test the installation, you can run the following commands from the samples/wx +directory: +
+> ghc -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app --program=hello
+> ./hello
+
+ +

It is recommended to read the notes on using wxHaskell with MacOS X.

+

+
wxhaskell-ghc6.0.1-0.2-2.i386.rpm (Red Hat Linux RPM, ghc 6.0.1)
+
A binary installer for Red Hat Linux with GTK2. Kindly provided by Jens Petersen. +
+
+
+ + +
+

Version 0.1 – 21 July 2003

+

All of these files are also directly available from the +sourceforge project page.

+

Basic packages

+
+
wxhaskell-doc-0.1.zip
+
Documentation and samples.
+
wxhaskell-src-0.1.zip
+
Source release of wxHaskell. See the building guide for installation instructions.
+
+ + +

Binary packages

+ +

The binary releases should be used with GHC 6.0. You need to download the documentation and samples separately.

+ +
+
wxhaskell-bin-msw-0.1.zip (Windows)
+
Unzip the release on top of the ghc install directory, for example c:\ghc\ghc-6.0. +After unzipping, click on the newly created wxhaskell-register.bat program to register +the wxHaskell package. (It is possible to install in a different directory than the GHC installation directory +but than you need to ensure that the wxhaskell bin directory is in your PATH).
+ +
wxhaskell-bin-mac-0.1.dmg (MacOS X)
+
An installer for MacOS X. Note that is installer can only be used with GHC version 6.0 (and higher?). +The installer also contains documentation and samples. The installer copies the wxHaskell libraries to /usr/local/wxhaskell and registers them with GHC. + +

To test the installation, you can run the following commands from the samples/wx +directory:

+
+> ghc --make -package wx HelloWorld.hs -o hello
+> /usr/local/wxhaskell/bin/macosx-app --program=hello
+> ./hello
+
+ +

Don't forget to read the notes on using wxHaskell with MacOS X. +To uninstall wxHaskell type:

+
+> rm /usr/local/wxhaskell
+> ghc-pkg -r wxcore
+> ghc-pkg -r wx
+
+
+
+
+ +
+toplast update: "May 8 2005". +
+ +
+ + addfile ./homepage/faq.html hunk ./homepage/faq.html 1 + + + + + + + +wxHaskell + + + + +
+ + + + +
+

Frequently Asked Questions

+

Technical

+
+
What is the difference between the wx and wxcore libraries?
+
The wxcore library provides the core interface to the wxWidgets API (in +WxcClasses). Furthermore, it provides some useful abstractions +for the Haskell programmer. However, the library just uses functional abstraction: no overloading, new monads, or other +fanciness. The wx library is build on top of the wxcore +library and uses more advanced abstraction mechanisms, like overloading, to provide useful features like +properties and attributes.
+ + +
Does wxHaskell support multiple threads?
+
Not currently. GHC 6.0 does not support process threads by default, and Haskell +concurrency does not work correctly (yet) with a GUI event loop. However, as the +wxWidgets manual says, multiple threads are not always a good solution. For example, +doing a long computation in a separate thread in order to show a progress bar, is +normally better solved by calling wxcApp(Safe)Yield periodically, +or by doing the computation in an idle event handler. +wxHaskell does have support for event driven, asynchronous input streams; see the Process sample +for more details. Note that one should use the wxHaskell provided mutable variables (Var) +to be assured for thread safeness in the future.
+
+ +

Design

+
+
Why haven't you created a purely functional interface (Fudgets, Fran, ..)
+
Since the design of high-level GUI libraries (like +Fruit or +Fudgets) is still +much of a research issue, we opted for creating a "medium level" interface: an interface that does +create useful functional abstractions but does not provide a new programming model (i.e. everything +is in the IO monad and uses simple mutable variables to communicate state across +different event handlers). Hopefully, this makes it easy for others to create new functional programming +models on top of the basic interface. However, in our experience, the current model is already quite +adequate and certainly much friendlier than the equivalent C++ code – having computations as first-class +values makes Haskell the ultimate imperative language :-) +
+ +
Why wxWidgets?
+
+Well, there are many good reasons for using wxWidgets: +
    +
  • wxWidgets is free software but you can still write commercial applications with it.
  • +
  • It is a thin wrapper around native UI elements giving native look-and-feel.
  • +
  • It is a comprehensive library that is portable across many GUI platforms.
  • +
  • There even exists a wxUniversal port that just uses a screen +buffer (and giving up on native look-and-feel!) that can be used on embedded devices.
  • +
  • The development community is very active (ranked among the top 25 of most active projects on sourceforge).
  • +
  • The library is mature (in development since 1992).
  • +
  • The library not only provides GUI abstractions but also an API for databases, sockets, editors, etc.
  • +
  • We could generate a Haskell marshalling layer automatically from the wxEiffel binding.
  • +
  • There exist many more language bindings, with wxPython as the most widely known (and used?).
  • +
+ +

But of course, there are also some downsides:

+ +
    +
  • wxWidgets is free software :-). In itself not bad but it also means that we are +dependent on the time and effort of volunteers. For example, the MacOS X port lags somewhat +behind and the documentation of the Qt toolkit is in general better +(although the wxWidgets documentation is pretty good too).
  • +
  • It is a huge library. Not a problem in itself but it can be somewhat intimidating.
  • +
  • The wxEiffel binding is only partially type checked and manually written; it is +better when the marshalling code can be generated from the real wxWidgets type signatures +(but alas, this involves writing either a C++ parser or writing bindings with SWIG). +We might someday start to use the wx.NET wrapper as it seems better structured for use +with an automatic marshalling program. +
  • +
+
+
Why don't you use Qt (or FLTK, or ..) ?
+
Of course there exist some other good GUI libraries and maybe they would be good +choices too (here is a nice overview). +However, many libraries have important drawbacks. For example, we do not use +the Qt toolkit since one has to pay for an expensive license to create commercial or +Windows applications; The programming model of Swing is inconvenient to use +from Haskell, etc. + +

More links: +Comparison of the FOX toolkit +against different GUI toolkits, including wxWidgets. +Comprehensive overview +of probably all GUI toolkits in existance. +

+
+
+
+ +
+toplast update: "Apr 1 2004". +
+
+ + + addfile ./homepage/index.html hunk ./homepage/index.html 1 + + + + + + + +wxHaskell + + + + +
+ + + + +
+

wxHaskell logo

+

+

wxHaskell is a portable and native GUI library for Haskell. The goal of the project +is to provide an industrial strength GUI library for Haskell, but without the burden of developing +(and maintaining) one ourselves.

+ +

wxHaskell is therefore built on top of wxWidgets – a comprehensive C++ library that is portable across all major GUI platforms; including GTK, Windows, X11, and MacOS X. Furthermore, it is a mature library (in development since 1992) that supports a wide range of widgets with the native look-and-feel, and it has a very active community (ranked among the top 25 most active projects on sourceforge).

+
+ +
+

Status

+

Since the core interface is generated +automatically from the wxEiffel binding, about 90% of the wxWidgets functionality is already supported, excluding more "exotic" widgets like dockable windows. Most work is currently directed into writing a Haskellized version of the wxWidgets API. The library currently supports Windows, GTK (Linux) and MacOS X. +

+
+ +
+

News

+
+
June 4, 2005
+
Lucas Torrećo, Emanoel Barreiros, Hilda Borborema, and Keldjan Alves have written a reversi game with wxHaskell. See the screenshots. +
+
May 8, 2005
+
A bug-fix update of version 0.9.4 is released. This update enables wxHaskell with the GHCi 6.4 interpreter on Windows platforms. +
+
May 7 2004
+
wxWidgets news: The wxWidgets library (as well as wxPython and wxPerl) is being bundled as part of recently released Mac OS X Tiger operating system. Furthermore, there are three interesting new wxWidgets products: Bitwise IM is a cross-platform encrypted instant messenger application. Kynosoft recently released magic splitter, a file splitter and checksum utility. Finally, Lit Window Productions released wxVisualSetup 2.6 which integrates wxWidgets into the Microsoft Visual Studio .NET IDE. +
+
May 3, 2005
+
Version 0.9.4 is released. It comes with installers for +Fedora (Linux), Windows, and MacOSX. This is mostly an update to support the latest GHC 6.4. +
+
Feb 25, 2005
+
Version 0.9 is released. It comes with installers for +Fedora (Linux), Windows, and MacOSX. There is now support for printing and configuration files. Furthermore, there is much improved process support. Read the release notes for a detailed account of all changes. +
+
Nov 5 2004
+
Sander Evers has released Functional Forms: a library for wxHaskell to easily create dialogs to display and edit corresponding Haskell values. See the screenshot. +
+
Sep 23 2004
+
The technology behind the winners: +Team Dunkosmiloolump has used +wxHaskell for their submission to the Seventh annual ICFP programming contest – and they won the contest! See the screenshot. +
+
Jul 27 2004
+
Version 0.8 is released. It comes with installers for +Fedora (Linux), Windows, and MacOSX. There have been many bug fixes and many internal changes: managed resources are supported and all object references are checked. The wxGrid control is added and many other controls have a simplified interface. This version contains changes that are not backwards compatible but most are very small. Read the release notes for a detailed account of all changes. +
+
Jul 26 2004
+
Many internal changes: support for managed resources like bitmaps and full NULL pointer +checking on object pointers. Also added enhanced grid control support with wxGrid events (screenshot). +
+
Jul 24 2004
+
wxWidgets news: Elementec Software has released a very good backup program written in wxWidgets, Backup&Compress. It works great on Windows systems. +
+
Jul 22 2004
+
Wei Tan has made a graphical heap profile viewer for GHC with wxHaskell, called HPView. See the screenshots. +
+
Jun 8 2004
+
Team Dunkosmiloolump has used +wxHaskell for their submission to the Seventh annual ICFP programming contest. See the screenshot. +
+
Jun 4 2004
+
We are working towards version 0.8. This will support the new wxWidgets 2.5.2, and have many +improvements, like variable objects, NULL pointer checking and managed resources like bitmaps. +
+
May 10 2004
+
Support for radio menu items and file types in file save dialogs. +
+
Apr 2 2004
+
Version 0.7 is released. It comes with installers for +Fedora (Linux), Windows, and MacOSX. There have been some bug fixes, and more attributes are added to +influence style settings of windows. The build system has also improved, especially for Linux systems. +
+
Apr 2 2004
+
Eric Y. Kow has created a Wiki site for wxHaskell! +You are invited to add useful tips, screenshots, or example programs. +
+
Apr 2 2004
+
Sean Seefried has provided a screenshot that +demonstrates the wxHaskell OpenGL +canvas using the HOpenGL binding +by Sven Panne. +
+
Mar 24 2004
+
Updated screenshots and added screenshots of wxHaskell applications. +wxHaskell also builds properly now with wxWidgets 2.5.1 and can link statically with the wxWidgets libraries. +Menu bugs on MacOS X have been fixed. +
+
Feb 29 2004
+
The windows installer of wxHaskell 0.6 has been updated to better support +windows98 and windows95 platforms. +
+
Feb 23 2004
+
Version 0.6 is released. This version fixes many outstanding +bugs, has basic support for MDI applications, and compiles with the latest CVS snapshots of wxWidgets. +
+
Feb 20 2004
+
wxWidgets news: wxWindows changes its name into wxWidgets! Microsoft has requested this change and, +in exchange, provides modest financial support for further development of wxWidgets +(read more). +
+
Feb 20 2004
+
wxHaskell is compiled with the latests CVS snapshot of wxWidgets on MacOS X 10.3 (Panther) with GHC 6.2. +The snapshot still contains menu bugs on the Mac though. Also added a convenient installer for the +readline library to make the build process on the Mac relatively painless. +
+
Feb 20 2004
+
Finally! the resize bugs have been found and fixed. Furthermore, support for MDI windows is added. We are +working towards a 0.6 release in the next week. +
+
Feb 19 2004
+
A patch to the windows installer of version 0.5 is released (named ...-0.5-1). +
+
Feb 14 2004
+
Version 0.5 is released. This is basically a patch-level +release for GHC 6.2. Also added support for html window events. Unfortunately, there are still some resize bugs. +
+
Dec 22 2003
+
wxWidgets news: wxWidgets on mobile phones! (using the Borland C++ builder Nokia edition on series 60 phones with the Symbian OS). +
+
Dec 19 2003
+
wxWidgets news: wxWidgets get its own software foundation to promote and protect wxWidgets' interest. The foundation is chaired by Mitch Kapor, now leading the Open Source Applications Foundation (OSAF) (which is using wxWidgets for their Chandler product). +
+
Dec 18 2003
+
wxWidgets news: The new Borland Builder-X development environment for C++ will ship with wxWidgets as its windowing toolkit. Read the official wxWidgets statement, and take a look at a screenshot from the pre-evaluation version. +
+
Nov 7 2003
+
Version 0.4 is released. Most important addition is extensive ODBC database support (not yet on MacOS X) and improved installation on windows. Resize issues have been fixed. +
+
Oct 30 2003
+
Extensive support for portable ODBC database access has been added. +Includes functionality to retrieve full meta information about databases and result sets. +At the moment only tested on Windows with MS SQL Server and MS Access, and unsupported on MacOS X.
+
Oct 25 2003
+
Support for the openGL canvas has been added, and we are looking for volunteers +to test it with HOpenGL. At the moment unsupported on MacOS X.
+
Oct 9 2003
+
Cover of the magazineHaskell on the cover of magazine! wxHaskell is featured in the october 2003 edition of L'informaticien – a popular French PC magazine. The article has been written by Frédéric Mazué. I have added +some screenshots of the relevant pages. +
+
Oct 1 2003
+
Version 0.3 is released. This is a patch-level release against the new wxWidgets 2.4.2 +library. Behaviour is especially improved on MacOS X. Also contains new functionality to manipulate pixel buffers +directly. +
+
Sep 26 2003
+
Jens petersen kindly provided a rpm for Red Hat Linux. +
+
Sep 16 2003
+
Version 0.2 is released! The new release has (improved) support for tree controls, list +controls, toolbars, splitter windows, sliders, gauges, and bitmap +buttons. Screenshots of these widgets on different platforms have been +added to the website. Furthermore, there are numerous small bug fixes, +especially for wxGTK. +
+
Sep 15 2003
+
Fixed numerous small bugs after extensive testing on GTK and MacOS X. Issues on GTK: tree control has the wrong size (looks bulky), unable to run main twice from ghci. +
+
Sep 11 2003
+
Improved support for toolbars, sliders, and gauge controls. +
+
Sep 10 2003
+
Improved support for tree controls, list controls, image lists, and splitter windows (i.e. sash bars). See the screenshots. +
+
+
Aug 22 2003
+
wxWidgets news: AOL has released AOL Communicator, built with a modified version of wxWidgets. An article about AOL Communicator can be found on Quote.com. +
+
Aug 21 2003
+
wxHaskell has been build with GHC version 6.0.1. (GHC versions 6.0, 5.04.3, and interim 5.05 were +already supported). +
+
Aug 19 2003
+
Sweeping changes: renamed the library WXH to the more appropiate +name WXCore. Also fixed type signatures in the marshalling of tree controls, list controls, toolbars and splitter windows. +
+
Aug 18 2003
+
Arthur Baars has provided a proper +installer for MacOS X now. +
+
July 22 2003
+
There is a binary release for MacOS X now. Furthermore, the source release (version 0.1) has been +updated with a small bug fix in the configure script that caused build problems on Linux systems. +
+
July 21 2003
+
We are proud to announce the first public release of wxHaskell 0.1! There is even a binary distribution +for Windows. +
+
July 18 2003
+
Added two more screenshots: Proxima (by Martijn Schrage) and Tha-Simulator (by Wijnand Suijlen). +
+
July 14 2003
+
Close to the first release, we have updated the build system: all projects are now +build with a single makefile and configure script, and distributions are automatically generated. +The new development tree is in the wxhaskell directory: the other directories are +now considered obsolete (wxc, wxdirect, wxh, and wx). +
+
July 9 2003
+
wxHaskell now runs properly on MacOS X!. It still contains some small +redraw problems with resizeable dialogs but all the samples work ok. +
+
July 9 2003
+
The wxc library compiles now with Microsoft Visual C++ on windows platforms. The +resulting dynamic link library is just 600kb (while the gnu compiled libraries are 2mb). +
+
July 3 2003
+
The wx library is available through sourceforge now. +
+
July 2 2003
+
A major revision of the wxHaskell library has been committed – all the this pointers +are now passed as the first argument instead of the last. +
+
July 1 2003
+
wxHaskell has been used in the ICFP contest +by Team Dom +to create a graphical editor for solving the tracks. There is a nice +screenshot of the editor running on GTK/Linux. +
+
June 4 2003
+
Arthur Baars has kindly provided his Linux machine and his time!, to build wxHaskell successfully on MacOSX (see the screenshots). Unfortunately, drawing device contexts +do not work at this moment. +
+
June 3 2003
+
We started working on make files for mingw32 (win32), unix, and MacOSX. Alpha release scheduled for the first week of July. +
+
Apr 22 2003
+
Andres Löh has kindly provided his Linux machine (and his time :-), to build wxHaskell successfully with GTK. Screenshots have been added. We have some small problems with mouse motion events on GTK though (May 20 2003 update: the problems are gone with the +latest (cvs) GHC version). +
+
Feb 18 2003
+
Preliminary documentation on the wx library added. +
+
Feb 1 2003
+
Put the wxHaskell project on sourceforge. +
+
+
+ +
+

+ SourceForge.net Logo + Valid HTML 4.0! + Valid CSS! + + + + + + +

+
+ +
+toplast update: "Jun 5 2005". +
+
+ + + addfile ./homepage/license.html hunk ./homepage/license.html 1 + + + + + + + +wxHaskell - License + + + + +
+ + + + +
+

License

+

The wxHaskell libraries are distributed under the wxWindows library license. +The documentation is subject to the wxWindows documentation license.

+ +

See http://www.wxwidgets.org/newlicen.htm +for the legal description of the license.

+ +

The wxWindows library licence is essentially the L-GPL (Library General Public Licence), +with an exception stating that derived works in binary form may be distributed on the +user's own terms. This means that it is possible to create commercial software with this +library without paying royalties or disclosing source code. This is a solution that satisfies +those who wish to produce GPL'ed software using wxHaskell, and also those producing proprietary software. +

+ +

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the wxWindows library license for more details.

+
+ +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/main.css hunk ./homepage/main.css 1 +/* adjust padding of body to predictable values */ +/* stale blue: rgb(126,165,193) + light gray: rgb(208,208,208) +*/ +body { background-color: rgb(126,165,193) ; margin: 0pt; padding: 0pt; } +#body { margin: 0pt; padding: 2% 0pt 0pt 0pt } + +/* menu items (added sans-serif, 8pt for better viewing on the safari browser) */ +.menu, .status, .side, .quicklink, .quicklinks + { font-family: sans-serif + ; font-size: 8pt + ; font: menu + } + +/* a side box */ +.side, .menu + { margin: 0pt 1em 1em 1% + ; padding: 2pt + ; float: left + ; clear: left + ; width: 2.25cm + } + +/* centered text */ +.text, .status + { margin: 0pt 10% 1% 13% + ; padding: 0pt 2% 0pt 2% + } + + +/* boxes */ +.text, .status, .side, .menu + { border-style: solid; border-width: 1px + ; background-color: white + } + +img { border-style: solid; border-width: 1px } + +/* needed to make opera behave the same as IE */ +.text p { margin-bottom: 1em } + +/* menu items (netscape needs padding set to 0pt) */ +.menu ul { margin: 0pt; padding: 0pt } +.menu ul ul { margin-left: 1em; padding: 0pt } +.menu li { margin: 0pt; list-style: none } +.menu li li { margin: 0pt; list-style: none } + +.menu a, .status a + { text-decoration: none } + +/* tweaks */ +li li { list-style: disc } + +h1, h2 { text-align: center + ; margin-top: 1ex + /* + ; font-family: verdana, sans-serif + ; font-weight: normal + */ + } + +.lib { font-variant: small-caps; color: navy } +code { color: navy } + +dt { font-weight: bold } +dd { margin-bottom: 1ex } addfile ./homepage/menu.html hunk ./homepage/menu.html 1 - + + addfile ./homepage/quickstart.html hunk ./homepage/quickstart.html 1 + + + + + + + +A quick start with wxHaskell + + + + +
+ + + + + +
+

A quick start with wxHaskell

+ +

This document is written to get you started quickly with writing wxHaskell applications. +Further documentation can be found on the documentation page. +

+ +

Note from the author: I have written this page to be in close correspondence with the +yahu getting started page – +first of all to make my job easier by reusing +Koen Claessen's excellent example, but also since +it makes an interesting comparison: we reuse many concepts of yahu, most notably properties +and attributes, but as yahu is based on Tcl/TK, the applications are also +typed and structured in a fundamentally different way.

+ +

Daan Leijen

+
+ +
+

Hello world in wxHaskell

+

Start your favorite editor and write the following program (that will show a frame with +a single button that closes the frame when pressed).

+Hello world on Windows XP +
+module Main where
+import Graphics.UI.WX
+
+main :: IO ()
+main
+  = start hello
+
+hello :: IO ()
+hello
+  = do f    <- frame    [text := "Hello!"]
+       quit <- button f [text := "Quit", on command := close f]
+       set f [layout := widget quit]
+
+Hello world on Red Hat Linux + +

Now start GHCi and run the program:

+
+> ghci -package wx Hello.hs
+[snip]
+Loading package wx ... linking ... done.
+Compiling Main ( Hello.hs, interpreted )
+Ok, modules loaded: Main.
+*Main> main
+
+ +

Note: On MacOS X, you can only use the interpreter with special scripts, +as you need to build MacOS X applications. +Normally, the following commands will do the job:

+Hello world sample +
+> ghc -package wx -o hello Hello.hs
+> /usr/local/wxhaskell/bin/macosx-app -v hello
+> ./hello
+
+ +

You can read the MacOS X +notes for more information on using wxHaskell on MacOS X, +and how to use it from an interpreter prompt.

+ +

Types

+

A typical wxHaskell program imports the Graphics.UI.WX library. If you need to access +specific wxWidgets functionality, you would also import the lower level Graphics.UI.WXCore library. +The main function uses start to start our GUI. The function start +initializes the GUI framework with the provided argument and starts the window event loop until the application +quits or when all top-level windows are closed. The GUI itself is described with the following functions: +

+
+frame  ::             [Prop (Frame ())] -> IO (Frame ())
+button :: Window a -> [Prop (Button ())] -> IO (Button ())
+
+text   :: Attr (Window a) String
+layout :: Attr (Frame a)  Layout
+
+(:=)   :: Attr w a -> a -> Prop w
+set    :: w -> [Prop w] -> IO ()
+
+command:: Event (Control a) (IO ())
+on     :: Event w a -> Attr w a
+
+widget :: Window a -> Layout
+
+ +

Actually, some of these functions have (even) more general types – you can use the :t +command in GHCi to see them.

+

The types Frame () and Button () denote graphical objects. These objects can +have properties. When an object is created we can supply an initial list of properties but we +can also set them later using set. The type of properties for frames are +Prop (Frame ()) and for buttons Prop (Button ()).

+ +

Properties are created by combining attributes with values. Examples of attributes are +text and layout. An attribute of type Attr w a applies to objects +of type w and values of type a. Values can be assigned to attributes using the +(:=) operator. You can find out more about attributes in the haddock documentation +for the modules WX.Attributes and +WX.Classes.

+ +

Somewhat special attributes are events. An event of type Event w a can be +transformed into an attribute Attr w a using on. The value of an event +attribute is normally an IO action that is executed when the event happens. +Find out more about events in the haddock documentation for +WX.Events and the lower level +WXCore.Events

+ +

Since wxHaskell is based on an object-oriented framework, we also encode inheritance. The extra +type parameter of objects encodes the inheritance relationship. When the parameter of an object is +unit (), it denotes an object of that exact class. When the parameter is a type variable +a, it denotes any object that is instance of that class. For example, both the frame +and button functions return precisely a frame or button and use a () type parameter. +However, the text attribute applies to any kind of window, including frames and buttons, and +has a Window a as its argument. We can now use the text attribute for example +for both frames and buttons. In wxHaskell, this works since a Frame () is actually a type synonym for +Window (CFrame ()) and can thus be passed where a Window a is expected. +The same hold for a Button () that is a synonym for Control (CButton ()) +that is again a synonym for Window (CControl (CButton ())).

+ +

Layout

+ +

The layout of a window is specified through the layout attribute. The layout of the +current program is rather terse and we will spice it up by letting the button float in the center +when the window is resized. This is also a good opportunity to add a small margin around the button.

+Hello world sample +
+set f [layout := margin 10 (floatCentre (widget quit))]
+
+ +

We can also add a text label above the button that is also centered. The argument of column +specifies the amount of space between the items.

+Hello world sample +
+set f [layout := margin 10 (column 5 [floatCentre (label "Hello")
+                                     ,floatCentre (widget quit)
+                                     ] )]
+
+ +

You can find out more about layout in the documentation for the +WXCore.Layout module.

+
+ +
+

Bouncing balls

+ +

It is time for a more fun program that our Hello sample. We will write a program that lets us +bounce balls on the screen!

+

+Bouncing balls on Windows 2000 +Bouncing balls on Gentoo Linux with GTK and KDE +Bouncing balls on MacOS X (Panther) +Bouncing balls on Red Hat Linux (Fedora) +

+ +

Note that the bouncing balls window is not resizeable, with the maximize box greyed out on windows. +First we look at the main function in our program – ballsFrame:

+
+module Main where
+import Graphics.UI.WX
+
+-- constants: radius of the ball, and the maximal x and y coordinates
+radius, maxX, maxY :: Int
+maxY = 300
+maxX = 300
+radius = 10
+
+-- the max. height is at most max. y minus the radius of a ball.
+maxH :: Int
+maxH = maxY - radius
+
+--the main function
+main = start ballsFrame
+
+ballsFrame
+  = do -- a list of balls, where each ball is represented
+       -- by a list of all future positions.
+       vballs <- varCreate []
+
+       -- create a non-user-resizable top-level (orphan) frame.
+       f <- frameFixed [text := "Bouncing balls"]
+
+       -- create a panel to draw in.
+       p <- panel f [on paint := paintBalls vballs]
+
+       -- create a timer that updates the ball positions
+       t <- timer f [interval := 20, on command := nextBalls vballs p]
+
+       -- react on user input
+       set p [on click         := dropBall vballs p              -- drop ball
+             ,on clickRight    := (\pt -> ballsFrame)            -- new window
+             ,on (charKey 'p') := set t [enable   :~ not]        -- pause
+             ,on (charKey '-') := set t [interval :~ \i -> i*2]  -- increase interval
+             ,on (charKey '+') := set t [interval :~ \i -> max 1 (i `div` 2)]
+             ]
+
+       -- put the panel in the frame, with a minimal size
+       set f [layout := minsize (sz maxX maxY) $ widget p]
+   where
+     ...
+
+ +

Unlike more functional GUI libraries, wxHaskell does not provide a model for state management and uses +simple mutable variables to communicate state across different event handlers. (Note: this is a concious +design decision – as functional GUI interfaces are still very much a research area, we +want to provide a full fledged GUI library using simple IO first, than try to build good +functional interfaces on top of that). The state of the bouncing balls demo is a list of balls. Each ball +is represented as a list of all its future heights. At the start of the program the list is empty +(varCreate []).

+ +

Next, we use fixedFrame to create a non-resizeable window frame. A panel is created to +paint the balls on and its paint handler paints the current balls in the panel. (Note: +a panel has nothing to do with a Java panel: it is a widget that is normally used to place controls in +as it manages control navigation keys like tab).

+ +

To animate the balls, we install a timer that advances all the balls on each timer tick and +causes the panel to repaint the balls. We also install event handlers that react on the user: a mouse +click causes a new ball to drop, a right click opens another frame (!), a p-key pauses the +balls, and +/- increase/decrease the speed of the balls. Note how the operator +(:~) applies a function to an attribute value instead of assigning one. Thus, the +expression (set t [enable :~ not]) flips the enabled state of the timer.

+ +

Finally, we specify the layout of the frame, using minsize to specifiy the minimal size +of the panel and thus the size of the frame as it is not resizeable.

+ +

Painting

+ +

Let us look at the paint event handler of the panel:

+
+    -- paint the balls
+    paintBalls :: Var [[Point]] -> DC a -> Rect -> IO ()
+    paintBalls vballs dc viewArea
+      = do balls <- varGet vballs
+           set dc [brushColor := red, brushKind := BrushSolid]
+           mapM_ (drawBall dc) [p | (p:ps) <- balls]
+
+    drawBall dc pt
+      = circle dc pt radius []
+
+ +

A paint event handler gets two arguments: a device context (DC) to draw on and a +rectangle that specifies the coordinates of the viewing area. +We have supplied the first argument ourselves when setting the event handler, namely the mutable +variable that holds the list of all balls.

+ +

As said, a single ball is represented as a list of all its future positions. When painting the current +balls, we simple extract the head positions of all balls and draw them using drawBall. Drawing +combinators like circle draw using the current pen, brush, and font +of the device context. By default, a brush is transparent so we set it to a solid red brush before drawing +the circles. Note that this is an optimization, we could have achieved the same effect by setting it for +each circle individually: circle dc pt radius [brushKind := BrushSolid, brushColor := red]. +You can read more about drawing in the documentation of the +WX.Draw module. +

+ +

Bouncing

+ +

The timer event handler uses nextBall to advance all the balls to their next postion.

+
+    -- advance all the balls to their next position
+    nextBalls :: Var [[Point]] -> Panel () -> IO ()
+    nextBalls vballs p
+      = do varUpdate vballs (filter (not.null) . map (drop 1))
+           repaint p
+
+ +

Updating the positions simply consist of dropping all initial positions and filtering out all empty +lists. The function repaint is used to invoke the paint event handler of the panel.

+ +

When a users clicks on the panel, a new ball is created in dropBall.

+
+    -- drop a new ball, gets mouse position as last argument
+    dropBall :: Var [[Point]] -> Panel () -> Point -> IO ()
+    dropBall vballs p pt
+      = do varUpdate vballs (bouncing pt:)
+           repaint p
+
+    -- calculate all future positions
+    bouncing (Point x y)
+      = map (\h -> Point x (maxH-h)) (bounce (maxH-y) 0)
+
+    -- calculate all future heights
+    bounce h v
+      | h <= 0 && v == 0 = replicate 20 0 -- keep still for 20 frames
+      | h <= 0 && v  < 0 = bounce 0 ((-v)-2)
+      | otherwise        = h : bounce (h+v) (v-1)
+
+ +

We prepend a new list of ball positions to the existing list using the varUpdate function +and we repaint the panel. The new list of positions is calculated with the bouncing function +that takes the position of the mouse pointer as its argument. This function uses the bounce +function to calculate all future heights given an initial height and speed. Each time the ball touches +the ground, it loses 2 units of speed.

+ +

Hopefully this sample inspires you to write more interesting GUI's. Don't forget to look +at the samples provided with the wxHaskell documentation.

+
+ + + +
+toplast update: "Apr 1 2004". +
+ +
+ + addfile ./homepage/samples.html hunk ./homepage/samples.html 1 + + + + + + + +wxHaskell + + + + +
+ + + +
+

Screenshots

+

Here are some screen shots of examples that are included in the wxHaskell library. +The screenshots are taken on various Linux, Windows, and Mac OS X systems. When the screens look differently it is normally due to differences in the native look-and-feel of a platform. Many differences are intentional – one +can normally specify the exact appearance if needed.

+
+ +
+

Hello world +[source wx, +source wxcore]. Let's start with the infamous "Hello World" application. +Note how the status bar reflects the menu option. (Note: The "File" menu disappears on the Mac as both menu items are +moved to the standard Mac application menu.) +

+

+Hello world on Windows 2000 +Hello world on GTK (KDE/Linux) +Hello world on MacOS X (Panther) +Hello world on Red Hat Linux (Fedora) +

+
+ +
+

Image viewer +[source wx, +source wxcore]. This example uses a standard file open dialog to open image files in various +formats (jpg, gif, png, bmp etc.) and displays them. The windows example shows an image of a notorious Norwegian Haskell hacker skiing on mount Hood. Note the custom application icon.

+

+ + + + + + + +
That Barton Fink feelingImage viewer on MacOS X
Windows XPMacOS X
+

+

And an extended imageviewer with a toolbar and statusbar: +

+ + + + + + +
Image viewer on Windows XPImage viewer on Red hat linux with GTK
Windows XPRed Hat Linux with GTK
+
+

+
+ + +
+

Time flows +[source wx]. An old Fran demo! This sample shows how to use the idle event handler to implement a +resource aware and responsive GUI that still performs heavy animation. A nice sample to practice on: extend it +yourself with menus, status bars, and options dialogs.

+ +

+ + + + +
Time flows like a river on windows XPExtended time flows like a river on Linux/GTK
Basic sample on Windows XPExtended sample on Red Hat Linux with GTK
+
+Extended time flows like a river on MacOS X +

Extended sample on MacOS X

+

+
+ + +
+

Controls +[source wx]. A sample that shows different standard controls, like buttons, listboxes, sliders, radio buttons, etc. +

+

+ + + + + + +
Controls sample on Red Hat Linux (Fedora)Controls sample on Windows XP (Classic)
Red Hat Linux (Fedora)Windows XP (Classic look)

+Controls sample on MacOS X (jaguar) +
+MacOS X (Jaguar) +
+Controls sample on MacOS X (panther) +
+MacOS X (Panther) +

+
+ + + +
+

FileBrowse +[source wx]. A (very) simple file browser that demonstrates the use of tree controls, list controls and splitter windows. +

+

+File browser on windows XP +
+ +File browser on MacOS X (Panther) +
+File browser on Red hat linux with GTK +

+
+ +
+

Grid +[source wx]. Simple demo of the wxGrid control and wxGrid events. +

+

+Grid demo on windows XP +Grid demo on Linux (Fedora) with GTK +Grid demo on MacOS X (Panther) +

+
+ +
+

OpenGL [source contrib]. +Sean Seefried and Shelarcy have provided +these screenshots that demonstrate the wxHaskell OpenGL +canvas using the HOpenGL binding +by Sven Panne. +

+

+OpenGL Bezier Curve on Windows +
+OpenGL Bezier Curve on Windows.
+OpenGL Canvas on MacOS X +
+OpenGL Cone on MacOSX (Click image to enlarge) +

+
+ + + + + +
+toplast update: "Jul 27 2004". +
+
+ + + addfile ./homepage/screenshots.html hunk ./homepage/screenshots.html 1 + + + + + + + +wxHaskell + + + + +
+ + + +
+

Screenshots

+

Here are some screenshots taken on various Linux, Windows, and MacOS X systems:

+

+

+
+

+
+ +
+

+Some screenshots of wxHaskell programs

+
+ +
+toplast update: "Apr 1 2004". +
+
+ + + }