1

我发现使用模式匹配是eval (App x y)多余的,因为两种情况都会返回App x y. 我想知道是否eval (App x y)需要,因为我们eval x = x最后有,其中还应该包括eval (App x y)

data Expr = App Expr Expr | S | K | I | Var String | Lam String Expr deriving (Show,Eq)
eval :: Exp -> Exp
eval (App I x) = eval x 
eval (App (App K x) y) = eval x
eval (App (App (App S f) g) x) = eval (App (App f x) (App g x))
eval (App x y)
 | evalx == x  = (App evalx (eval y)) --test if x is a Lam (not other possible values of Exp)
 | otherwise = eval (App evalx y)
     where evalx = eval x
eval (Var x) = (Var x)
eval x = x  
4

0 回答 0