Skip to content

Instantly share code, notes, and snippets.

@kseo
Last active December 15, 2016 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kseo/3a33d9b16565079fe409 to your computer and use it in GitHub Desktop.
Save kseo/3a33d9b16565079fe409 to your computer and use it in GitHub Desktop.
GADT
{-# LANGUAGE GADTs #-}
data Expr a where
I :: Int -> Expr Int
B :: Bool -> Expr Bool
Add :: Expr Int -> Expr Int -> Expr Int
Mul :: Expr Int -> Expr Int -> Expr Int
Eq :: Expr Int -> Expr Int -> Expr Bool
eval :: Expr a -> a
eval (I n) = n
eval (B b) = b
eval (Add e1 e2) = eval e1 + eval e2
eval (Mul e1 e2) = eval e1 * eval e2
eval (Eq e1 e2) = eval e1 == eval e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment