background preloader

Haskell

Facebook Twitter

24 Days of Hackage: snap. The Snap framework is one of a handful of web frameworks available for Haskell, and comes complete with a high performance HTTP server, a rich monad for web programming, composable snaplets, and strong integration with the Heist templating language.

24 Days of Hackage: snap

In today’s post, we’ll have a look at how simple it is to build applications using Snap. snap-core The first library we’ll look at is snap-core, which provides some low level tools for building dynamic websites. Let’s jump straight in to getting some results. A simple web handler is simply a function in anything that is an instance of MonadSnap: hello :: Snap () hello = writeText "Hello, world! " Hello world doesn’t get any simpler than that! App :: Snap () app = route [("/hello", hello)] This adds a single route to our application, if the user browses /hello, then Snap will use our hello handler, and simply write “Hello, world” back to the browser. Main :: IO () main = quickHttpServe app Snaplets. Web/Frameworks. Content from Web should be merged here.

Web/Frameworks

Below is a list of known to be active Haskell web frameworks. Rather than one framework to rule them all, Haskell provides several options. You can view the Web/Deploy page to get an idea of how you might deploy an application written in some of these frameworks. See also: there are also many inactive web frameworks to draw inspiration from 1 Happstack Happstack is a Haskell web framework. Happstack is a complete web framework. Safecopy: datatype serialization and migration support acid-state: a powerful NoSQL ACID storage system with native support for Haskell types It also includes integration with many 3rd party libraries including: templating: Blaze HTML, Hamlet, HSP, HStringTemplate, Heist, and more forms: reformrouting: web-routes type-safe urls and routing databases: can be used with most Database interfaces with no special support required 2 Snap 3 Yesod. Yesod Web Framework for Haskell. IO inside. Haskell I/O has always been a source of confusion and surprises for new Haskellers.

IO inside

While simple I/O code in Haskell looks very similar to its equivalents in imperative languages, attempts to write somewhat more complex code often result in a total mess. This is because Haskell I/O is really very different internally. Haskell is a pure language and even the I/O system can't break this purity. The following text is an attempt to explain the details of Haskell I/O implementations.

This explanation should help you eventually master all the smart I/O tricks. If you are new to Haskell I/O you may prefer to start by reading the Introduction to IO page. 1 Haskell is a pure language Haskell is a pure language, which means that the result of any function call is fully determined by its arguments. Let's compare this to C: optimizing C compilers try to guess which functions have no side effects and don't depend on mutable global variables.

PutStrLn "Press any key to begin formatting"