Thursday, May 3

Online Haskell typechecker

Last weekend I put up, which is basically a thin web frontend over ghc, the Haskell compiler. It is limited to one Haskell module, but it makes the experience of studying Haskell much more pleasurable by running the typechecker in the background as you type. Plus, it is web-based - no local installation necessary!

The thing about Haskell is that it has a fabulous type system which can weed out a broad class of bugs at compile time. However, the usual interfaces with the compiler leave a lot to be desired. Vim + ghci in a terminal of course works, but I have already been spoilt by IDEs, and the "Alt-Tab; Up; Enter; wait; Alt-Tab + jump to line manually" dance does not appeal to me at all. Emacs integration might be better, but I do not know emacs well, and it is never a good idea to start learning two things at the same time.

Note: I suspect that many of the problems I encountered were due to the fact that I use MacOSX.

I have looked a few of the existing IDEs, but that did not go well. EclipseFP did not offer any benefits over a text editor at all. I found a blog post saying that implied that it would work better with a newer version of GHC. Cue a few hours of reinstalling GHC and compiling Haskell packages, and I got the system set up, but that made the situation even worse. Eclipse would simply crash on startup every time until I wiped the configuration directory clean. So much for EclipseFP.

I also tried Leksah. At least it did not crash, nevertheless, I found it quite unwieldy, especially for learning purposes. The autocompletion is broken in annoying ways. For example, if you type "f a = a", Leksah will autocomplete the second "a" into "as". It took me a while to discover an error in my program that was due to this autocorrection mechanism.

Leksah does have a "compile in background" mode, which was admittedly a source of inspiration for, but the implementation is subpar. It simply invokes the compiler and simply redirects the output to a display pane on the window. As you write code, the text in the pane constantly scrolls, which is very distracting. The implementation is also buggy. Occasionally errors are interleaved with status output:

There is also, but it does not work not nearly as well for Haskell as its cousins and do for Python and Ruby, respectively. All are limited to evaluating expressions, but in Python/Ruby that actually gets you a long way, while nontrivial Haskell programs are complex static structures that are unwieldy without a persistent text editor.

Despite all the trouble, which, again, probably has to do with my choice of MacOSX, these issues do not detract from the beauty of Haskell as a language. If you are interested, I can heartily recommend as very good reading material, and Tony Morris's course exercises (in combination with for practice.


joey said...

I enjoyed playing with your type checker yesterday.

FWIW, my haskell cycle consists of typing :mak in vim. ghc outputs line-numbers vim can understand and jump to errors. My Makefile detects if it's being run from vim ($VIM is set) and runs ghc -O0, which is much faster than production -O2 builds.

Gintautas Miliauskas said...

Yeah, :make in vim with errorformat is reasonable. I think I got spoilt by Eclipse, which just does its thing in the background and shows the results transparently. That is the perfect user interface in terms of input - no additional input is required.

By the way, according to ghc docs, -O0 is the same as not specifying any optimization options.

Diggory said...

Not a Haskell user (even if perhaps I should be), but kdevelop lets you hook up a custom makefile then just hit F8. Don't think it offers a lot over vim :make except a prettier editor.

Rob Stewart said...

Excellent stuff!

1) Can one use imports for other libraries? (and if so, how many libraries are installed on your server)

2) Is the code open source? Is it deployable locally?


Gintautas Miliauskas said...

The server has only the standard libraries, I think, but that should be enough for experimentation. Let me know if it's missing any essentials.

Cooperatve Computing said...

The article opened up my mind to an Inner creative me.Amazing and well written.