Sunday, February 25, 2007

About losing purity

Just so you don't think I've migrated to the Humanities Department - even though the last posts were about history, I'll finally get back to the technical stuff ;-) I'm currently working on a new example and a few API enhancements. Here's a few thoughts about a minor issue on the side:

When you are contributing Haskell code to Eclipse, via Cohatoe, the entry point so far had to look something like this (taken from the HelloWorld example):

import Cohatoe.API

resource = plugin {
pluginMain = sayHello

sayHello :: [String] -> [String]
-- and here goes your implementation of HelloWorld
I have been pondering for a while the question of purity in this. While I somewhat like having a pure function here ([String] -> [String]), I think for real world code what we want is rather something in the IO monad. This is not a technical problem (the code that loads pluginMain and executes it is in the IO monad anyway). It is just a question of API design. I think that in many cases the Haskell code will be used for doing things like reading source files, writing indices, and other such things that must be done in an IO action.

I have thought about enabling both (by passing, on the Java side, some flag that requests running in IO, or perhaps by making it something that you have to declare in the plugin.xml). However, this would load some more work on the user of the API, and I'd rather put a premium on simplicity here, seeing that we want to encourage programmers who don't know much about (or don't care much for) the Java and Eclipse side of things here. And Haskell programmers are used to having an entry point in the IO monad: the main function in every Haskell program is.

So, that settles it, from version 0.3 pluginMain will be of type [String] -> IO [String] :-)

No comments: