Archive for July, 2008

Experiments in Emacs

Saturday, July 26th, 2008

One of the most difficult challenges facing me when beginning to work with both Erlang and Haskell, was the significant lack of good IDEs… Well, at least that was the theory, anyway. Instead it turned out to be a real motivator to finally get around to investigating the only IDE that counts.

The real problem wasn’t that I couldn’t use Emacs for basic editing, rather I didn’t really have any idea how to use any of the extra features. Essentially it was like working with a semi-decent TextEdit.app, with code highlighting and unfamiliar keyboard shortcuts. Even after reading some of Steve Yegge’s essays I still didn’t really have any idea what I was doing.

Ok, so basically I’m now writing this in Emacs’ SGML mode and carefully trying to get around the perverse limitations of Wordpress. (Where the heck did the allow raw HTML checkbox go for author text?) Ironically I don’t think I’ve yet gained the productivity advantages from my efforts yet, but honestly that can probably just be attributed to a slow down in my typing speed and the rather unexpected work schedule I’ve been (you never realize just how much you appreciate sleep until you don’t get enough).

If I haven’t gained any real productivity, the question becomes why then am I still using Emacs to write this post? Well, as it turns out its not actually too bad for even when you don’t know all of the keyboard commands (all commands come from the keyboard, and most important commands really never migrate to them menu or at least don’t indicate they’re keyboard equivelent).

Even more importantly perhaps is the gains that I’ve achieved in other tasks…writing blog posts in Emacs may not be any faster for me (although I do seem to see much more of the post at any one time)…but writing code sure is. I seriously doubt that I’d change from using things like XCode for Cocoa applications or DrScheme for PLT Scheme applications (although I may change my mind on Scheme), but at least I have direct access to the REPL in Haskell and Erlang.

The way most of the editing modes in Emacs actually work, it essentially will even load up a file your working directly into a REPL running side by side in another text buffer. From there you can test smaller parts of your program or even just run the whole thing from the top if you needed to. Anyone who’s worked with a Lisp dialect or even Python or Erlang (among others) should be able to apreciate that.

There are a couple of things that have been bugging me so far. The first is the lack of a spell checker. Emacs does have built-in support for ispell, but as you probably guessed, it doesn’t work on my machine (actually it isn’t even installed on my cygwin install). Too make matters worse, I still need to teach Emacs how to find my Cygwin install and use programs from it before the windows paths…ugh…

And the other thing doesn’t even have anything to do with Emacs, but rather, its a limitation with the Haskell code I’m working on. Essentially I don’t have a framework for OpenGL work that allows me to substitute the code on my side of the framework after the application has been started…or more to the point I can’t stop the application after it has started, forcing me to quit the entire REPL every time I test the Game.

Of course the simple workaround is to just keep restarting the REPL or move out of Emacs into a Cygwin shell, but its still very inconvenient (damn you GLUT).

All in all I can only really see how it goes, but at the very least it should make life just that little bit easier. At worst, I’ll just have to resort to my aging Mac Powerbook (for the BSD layer).

Until next time…

– Lorenz

Monad Actions… ok… sure… whatever…!?

Sunday, July 13th, 2008

When I was first learning about OpenGL in Haskell it dawned on me that the example I was reading was doing some pretty crazy hung up things with Haskell style DSL techniques.

White this might make sense for a syntax based DSL (imho), I wasn’t sure this was absolutely necessary under OpenGL since the entire library is already just a bunch of monadic actions!?

Ok… that’s cool, maybe it was just overlooked, and I thus devised a test. Write a small piece of monadic code that re-evaluated an action over and over again…and it worked!!!

w00t!!!1one

uh… yeah… maybe you should just read this instead… save yourself some time and embarrassment ;)

IO Inside

One the upside… that game is still slowly progressing…

– Lorenz

Haskell Does Concurrency

Friday, July 4th, 2008

Ok, by now we all know that Object Oriented programming is likely to go the way of Erlang, or at least inherit an Actor model of language level concurrency.

In fact, I’ve even got an object system that I’m planning to implement just to find out how well this style of concurrency works in an Object Oriented programming language. The design of the language is even more post-Self/Slate than Newspeak (although I believe that this language will just complement the Smalltalk family of languages in all honesty).

Well then, Haskell…Haskell is actually very interesting, in this case by being one of the very few to push the limits of locking methods for concurrency rather than using the larger granularity involved in processes and message passing (not by much, but its still something).

The problem is that its impossible to write locking code by hand that doesn’t have at least one race condition hiding away in the corner. Not the ones you’ve already tested for, but the ones that would cause transactions to restart…like multiple threads locking a few items and then deadlocking…or even just managing the code required to restart deadlocks…yeah…lol…

Haskell provides a novel approach (its actually pretty old now, but it’s really only just starting to catch on, outside of Haskell anyway)… Software Transactional Memory.

STM is sometimes used in other areas of computing (OODBs, et ceteral), but the real gem here is that the Haskell type system nicely compartmentalized the side effects involved into a clever transaction form, within our imperative outer program. This makes working with transactions very much like the database stuff, only we’re only working with individual variables, so no complex table lookups.

Anyway, enough of my rambling, check it out:
Programming in the Age of Concurrency Software Transactional Memory

And if you haven’t already, remember to look at Erlang too…after all concurrency isn’t going away, and there are only two ways to get it right!

– Lorenz