Wednesday, June 3, 2015

Setting Up Snap with Haskell in Windows 8

Snap is a Web development framework for Unix systems, written in Haskell programming language. Snap has a high level test coverage it well documented.
It is a;
  • A fast HTTP server library
  • A sensible and clean monad for web programming
  • An HTML-based templating system for generating pages
Here I'm going to explain how Snap can be used to develop web applications in Haskell in a Windows 8 environment.
This is done using Cabal, a system written for building and packaging Haskell libraries. If you have not installed Haskell platform in your PC then please follow this link to download the platform. The installer will set up the Haskell environment once you run it and restart your PC.
To get on with the Snap open Command line and get the latest libraries in Cabal as follows;


And then,


Snap installs in ~/.cabal/bin

Restart your PC to add it to your path variable.

Now you're ready to start using Snap. To set up Snap,create a project.



The 'snap init barebones' sets up a simple HTTP framework, which you can work on. Now we have the following files in our project's folder;


To make the executable run the following command, which compiles our project and installs in ~/.cabal/bin.


To start your web-server type the following command in the terminal;


Now you're running a webserver on port 8000. You can change the by changing the value at the end of the command - 'websiteSample -p 1255'

Open up your web browser and go to 'localhost:8000' to see your website!

See what happens when you visit the end points;
        http://localhost:8000/foo
        http://localhost:8000/echo/bar