\begin{code}
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
module Mar29 where
\end{code}
do { x <- y ; z} ==> y >>= (\x -> z)
Learning objectives:
\begin{itemize}
\item meta-programming, Template Haskell (TH)
\end{itemize}
Good TH tutorial: https://markkarpov.com/tutorial/th.html
Basic idea: Quoting and Splicing
consider the expression “1 + 2”.
Quoted form: [| 1 + 2 |] — this is the AST, in Haskell of …
InfixE
(Just (LitE (IntegerL 1)))
(VarE GHC.Num.+)
(Just (LitE (IntegerL 2)))
InfixE
(Just
(LamE [VarP x_1]
(InfixE (Just (VarE x_1)) (VarE GHC.Num.+) (Just (LitE (IntegerL 1))))))
(VarE GHC.Base..)
(Just
(LamE [VarP x_2]
(InfixE (Just (V arE x_2)) (VarE GHC.Num.+) (Just (LitE (IntegerL 1))))))
Splice $( … ) evaluates an AST to a value