data Expr = I Int | Plus Expr Expr | Pair Expr Expr | Fst Expr | Snd Expr deriving (Show) data Value = VI Int | VPair Value Value deriving (Show) interpret :: Expr -> Value interpret (I i) = VI i interpret (Plus e1 e2) = case (interpret e1, interpret e2) of (VI a, VI b) -> VI (a + b) _ -> error "incompatible types" interpret (Pair e1 e2) = VPair (interpret e1) (interpret e2) interpret (Fst e) = case interpret e of VPair a _ -> a _ -> error "incompatible types" interpret (Snd e) = case interpret e of VPair _ b -> b _ -> error "incompatible types" main :: IO () main = print $ interpret $ Plus (Fst (Pair (I 2) (I 3))) (I 4)