In this recipe, we will work with GADTs. GADTs extend the data constructors, and allow us more expressivity for representing a complex structure such as a DSL. In this recipe, we will use GADTs to create an expression representation, and a simple parser.
Working with GADTs
How to do it...
- Create a new project working-with-GADTs with simple stack template:
stack new working-with-GADTs simple
- Open src/Main.hs. We will be adding our source here.
- Enable GADTs, and StandaloneDeriving:
{-# LANGUAGE GADTs, StandaloneDeriving #-} module Main where import Control.Monad import Data.Char import Control.Applicative
- GADTs take an algebraic data type one step further, and allow us to write data constructors explicitly...