Thursday, December 28, 2006

Simple example walkthrough I

In my last post I have pointed to the first preview of Cohatoe - so, how does one use it?

First of all a disclaimer: since this is a preview version, the usage of some of the APIs may change; this is so experimental that things may even change repeatedly. Of course I will make a notice of all changes to the APIs here, but before version 1.0 'API' just means 'candidate API'. The bright side of this is of course that it is also open for suggestions, so if you think the public interfaces of Cohatoe could be improved in a particular respect, please let me know.

Having said that, let me walk you through a very simple example usage of Cohatoe. In this first post, I will cover the basic installation and plugin development part of this. In a follow-up post we will then get to the Cohatoe-specific stuff (compiling the Haskell code, creating interfaces and classes for Eclipse).

As prerequisites, you need a Java 5 JRE, an Eclipse 3.2 (or higher) SDK installation and a GHC installation. I am myself currently using GHC 6.4.2 and the latest Eclipse 3.3 milestones. (You should be able to use other Haskell compilers, but I've not yet tried any.)

First of all, go to the download page and download the packaged update site archive and the cohatoe-api archive. Put them in some folder on your disk, say C:\cohatoetest\.

Fire up Eclipse and install the features in the update site archive, using Eclipse's update manager: select Help > Software Updates > Find and Install from the menu bar. Then choose Search for new features to install > New Archived Site, and browse to the downloaded file. Press OK and Finish. You get now a list of features to install:

Select all of them, press Finish and then confirm the licenses etc. etc., until Eclipse wants to restart. Confirm the restart too :-)

One of the features that you have just installed is the Cohatoe Examples feature. It contains some example code that demonstrates how to use Cohatoe, including the mandatory 'Hello World' menu item which you will find in the global menu bar right after the restart. You can use it to make sure that your installation of Cohatoe works. After clicking that menu item, you should see a dialog with a friendly message from Haskell:

In this example, we will just add another such 'Hello' menu item. It will evaluate a Haskell function and give the result of that computation to the user.

So let's first create a new plugin project. Select from the menu File > New > Project > Plugin Project, enter a name (like 'cohatoetest'), then press Next and again Next. Now select 'Hello world' and press Finish. We have now a Hello-World plugin that we can extend with some useful code. Before we look into the code, right-click the project and select Run As > Eclipse Application. A second Eclipse instance is now started that contains our newly created plugin project as runtime plugin, and you can see the 'Sample Menu' entry in the main menu bar. Make sure that it gives you a message box when clicking it:

The code that opens up this message box is in the SampleAction class:

and looks like this:

public void run( final IAction action ) {
"Cohatoetest Plug-in",
"Hello, Eclipse world" );

We will shortly replace the text in this message box with the result of a computation implemented in Haskell. Stay tuned :-)

(... to be continued)

1 comment:

Leif Frenzel said...

The continuation is here.