Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 1.33 KB

README.md

File metadata and controls

36 lines (25 loc) · 1.33 KB

Template Haskell Tutorial

This is the repository for a Template Haskell tutorial. See the proposal for the original inspiration.

Setup

Markdown Unlit is a GHC plugin for rendering Markdown as Literate Haskell. Exercises in this tutorial are written in Markdown, so we need to install the package.

stack install markdown-unlit

We will always test a module by loading it into GHCi:

stack ghci th-tutorial

Also recommend keeping a tab open to the docs for Template Haskell: https://www.stackage.org/lts-14.22/package/template-haskell-2.14.0.0

Exercises

The first two exercises are exploratory in GHCi to get a feel of how Template Haskell works. The next exercises go into more detail about how to define and test generated code.

  • Exercise01 explores "hello world" and TH nuances
  • Exercise02 helps create helper functions for inspection of a type's constructors at compile time.
  • Exercise03 uses the helper functions to generate instances for an enumeration.
  • Exercise04 demonstrates how to test the generated instances in Hspec.

Start in the src folder and fill in the TODO parts of each exercise. The solved directory contains hints and spoilers.