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?
CodePudding user response:
When GHCI displays a result as foo :: SomeType, it's telling you that the expression foo yielded a result of type SomeType, but it can't print any more details than that because SomeType does not support Show. Your function has therefore apparently returned some value successfully, but you don't know what value. You could inspect it by pattern-matching on the result. But you probably just want to add deriving Show to the type definition, so that GHCI can print the value it got.
