WAI development server (aka, skip the compiles)

September 14, 2010

GravatarBy Michael Snoyman

One of the most alluring advantages of dynamic languages is the rapid development cycle. When writing a web app in PHP, for example, you save your changes and see the results immediately. Us poor Haskellers are stuck compiling all the time.

Of course, it's not really true that PHP results are immediate. It's simply that PHP reinterprets your code automatically. But this perceived immediacy is very important. Having to switch back to a console to stop a process and start it up again is tedious.

So I've just released version 0.0.0 of wai-handler-devel. What it does is fairly simple: load up your code at runtime via hint, check for code changes every second and otherwise simply respond like a plain old simpleserver. This release has not been extensively tested, and has one known bug: it doesn't respond to a Ctrl-C on the console properly. Patches welcome; I just wanted to get this out the door quickly.

This package comes with a command line tool and a library. The library exports a single function, run, which happens to take the exact same arguments as the command line tool. These are the port number, the module name containing the application function, and the name of the application function. The only tricky thing is the type signature for the application function. Instead of simply using the WAI Application datatype, the function must have a type signature of:

withYourApp :: (Application -> IO ()) -> IO ()

By having this funny signature, it allows applications to be written in the with-style, making automatic resource management simpler. The Yesod scaffolding tool, for example, creates a function like this by default.

This code is very young, so please abuse it and make it break. This should hopefully make it much easier to test out WAI applications, and Yesod applications in particular.

Comments

comments powered by Disqus

Archives