Content area
Full Text
The Functional Web
The Snap Framework
A Web Toolkit for Haskell
Gregory Collins Google Switzerland Doug Beardsley Karamaan Group
Haskell is an advanced functional programming language. The product of more than 20 years of research, it enables rapid
development of robust, concise, and fast software. Haskell supports integration with other languages and has loads of built-in concurrency, parallelism primitives, and rich libraries. With its state-of-the-art testing tools and an active community, Haskell makes it easier to produce exible, maintainable, high-quality software. The most popular Haskell implementation is the Glasgow Haskell Compiler (GHC), a high- performance optimizing native-code compiler.
Here, we look at Snap, a Web-development framework for Haskell. Snap combines many other Web-development environments best features: writing Web code in an expressive high-level language, a rapid development cycle, fast performance for native code, and easy deployment in production.
Why Is Haskell Good for Web Programming?
Haskell lets you write elegant, high-level code that rivals the performance of lower-level, imperative languages. You can write declarative programs at a high level of abstraction and expressiveness, while still maintaining excellent performance. When you need to do bare-metal bit-twiddling or need access to a C library that doesnt yet have a Haskell equivalent, its foreign function interface lets you easily drop down to C.
Writing solid, real-world code is easier in Haskell than in other languages. It has strong static typing, so many common programming errors, such as null pointer exceptions, cant occur. You can separate an applications core logic from the parts that must interact with the outside world: pure functions in Haskell, given
the same inputs, always produce the same output. This property means that you almost always decompose a Haskell program into smaller constituent parts that you can test independently. Haskells ecosystem also includes many powerful testing and code-coverage tools.
Haskell also comes out of the box with a set of easy-to-use primitives for parallel and concurrent programming and for performance proling and tuning. Applications built with GHC enjoy solid multicore performance and can handle hundreds of thousands of concurrent network connections. Weve been delighted to nd that Haskell really shines for Web programming.
Whats Snap?
Snap offers programmers a simple, expressive Web programming interface at roughly the same level of abstraction as Java servlets....