How to do it...

  1. Create a new project, working-with-snaplets, with the simple stack template:
       stack new working-with-snaplets simple
  1. Add a dependency on the snap-core library in the build-depends subsection of the executable section, as follows:
  executable working-with-snaplets
    hs-source-dirs:      src
    main-is:             Main.hs
    default-language:    Haskell2010
    build-depends:       base >= 4.7 && < 5
                       , snap-core
                       , snap-server
                       , snap
                       , lens
                       , bytestring
                       , text
                       , mtl
  1. Open src/Main.hs. We will add our source here. After the initial Main module definition, add the necessary imports. Enable the OverloadedStrings and TemplateHaskell extensions, as Snap uses the Lens Template Haskell library:
{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}
module Main where ...

Get Haskell Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.