I'm currently writing a function for substitution (Lambda Calculus) based in Haskell.
data Term = Var String
| Application Term Term
| Lambda String Term
The function takes in a Term t1, String s and a Term t2. The function should replace every occurrence of s in t1 with t2.
subst :: Term -> String -> Term -> Term
subst (Lambda y e) x v = if x == y then (Lambda y e) else let e' = (subst e x v) in (Lambda y e')
subst (Var y) x v = if x == y then v else (Var y)
subst (Application e1 e2) x v = Application (subst e1 x v) (subst e2 x v)
When I try to call the function, I receive the following:
Input
subst (Lambda "x" (Application (Var "x") (Var "y"))) "y" (Var "f")
Output
subst (Lambda "x" (Application (Var "x") (Var "y"))) "y" (Var "f")
:: Term
Am I making an input error or is there a problem with my function?
:tin front, as in:t subst (Lambda ...)?