Permalink

Dynamic Applications From the Ground Up

31 AUG 2005

This paper describes an application architecture using hs-plugins which enables Haskell programs to dynamically load and reload modules. Hs-plugins also provides "eval" functionality. The resulting architecture allows for hot-swapping modules in a running program without any loss of data or state.

The authors describe using this plugin-based architecture to implement a text editor and an IRC robot. Each program only has a statically compiled core of around 100 lines of code; everything else is dynamically loaded. Of course, this is still Haskell - even though you're loading things dynamically, you still get the same type checking at module load time that you would get if you compiled it statically. Really outstanding work.

I especially liked this quote:

At this point, Haskell offers significant advantage over languages which encourage the use of global state. Unrestricted use of global state leads to a multitude of values scattered throughout the program; hence, bookkeeping of such a dispersed state becomes difficult and potentially infeasible. Hot swapping is only practical if the application already has disciplined use of global state as is the case by default in Haskell programs. Without restricted state, runtime system or operating system support seems necessary to deal with the state problem.