{-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures #-}
module GADT where
import Data.Function (on)
dataExpr a where I :: Int -> ExprInt B :: Bool -> ExprBool Bop :: Bop t a -> Expr t -> Expr t -> Expr a
dataBop :: * -> * -> * where Add :: BopIntInt Mul :: BopIntInt Eq :: Eq a => Bop a Bool
evalBop :: Bop t a -> Expr t -> Expr t -> a evalBopAdd x y = ((+) `on` eval) x y evalBopMul x y = ((*) `on` eval) x y evalBopEq x y = ((==) `on` eval) x y
eval :: Expr a -> a eval (I n) = n eval (B b) = b eval (Bop op x y) = evalBop op x y
x = I3 y = I2 r = [BopAdd x y, BopMul x y]
main = do mapM_ (print . eval) r print . eval $ BopEq x y print . eval $ BopEq (BTrue) (BFalse)