How to do it...

  1. Create a new project called working-with-persistent with the simple stack template:
        stack new working-with-persistent simple
  1. Add a dependency to persistent and persistent-sqlite, in the build-depends subsection of the executable section. Also add persistent-templatetext, and mtl (monad transformers) in the same section:
        executable working-with-persistent
          hs-source-dirs:      src
          main-is:             Main.hs
          default-language:    Haskell2010
          build-depends:       base >= 4.7 && < 5
                              , persistent
                              , persistent-sqlite
                              , persistent-template
                              , text
                              , mtl
  1. Open src/Main.hs. We will be adding our source here.
  2. At the top, we need to enable many extensions that are required for the persistent backend:
 {-# LANGUAGE EmptyDataDecls #-} {-# LANGUAGE FlexibleContexts ...

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.