Skip to content

CarstenKoenig/GadtParser

Repository files navigation

GADT Parser

simple but complete example on how to parse GADT-style expressions

data Expr (res :: Type) where
  IntE    :: Int -> Expr Int
  AddE    :: Expr Int -> Expr Int -> Expr Int
  BoolE   :: Bool -> Expr Bool
  IsNullE :: Expr Int -> Expr Bool
  IfE     :: Expr Bool -> Expr res -> Expr res -> Expr res

using Megaparsec

see the GADT-Module for details.

There is also a simple ADT implementation for comparision.

Build / Run / Test

This repository uses hpack and is tested with stack.

  • Clone this repository
  • cd into the project folder
  • run
    • stack build to build
    • stack run to run a simple "REPL" for the DSL
    • stack test to run the parser specs and doctests

I tried to document the modules so stack haddock --open should give you a nice looking documentation.