I am trying to create a function applications that will, when given a term N and a list of terms (X1,...,Xn) return N(X1,...,Xn)
But when I run my code, it shows the following error:
* Couldn't match type `Term' with `[Char]'
Expected type: Var
Actual type: Term
* In the first argument of `Lambda', namely `x'
In the expression: Lambda x (applications v xs)
In an equation for `applications':
applications v (x : xs)
| x == [] = Lambda x v
| otherwise = Lambda x (applications v xs)
|
147 | |otherwise = Lambda x (applications v xs)
But for some reason my applications function causes this error, even though it seems similar to my working abstractions.
applications :: Term -> [Term] -> Term
applications v [] = v
applications v (x:xs)
|x == [] = Lambda x v
|otherwise = Lambda x (applications v xs)
I would appreciate any help as I am new to this!
applicationsyou pass a list ofTerms, yourLambdalikely expects aVaras item in the head? Furthermore it should benull xsinstead ofx == []I guess, although that is likely not the "core problem".applicationsis also the opposite ofabstractionsbased on the description here. Here you should basically pattern match onLambda, and then replace the variable in the head of the lambda in the body of the lambda with the term.Termas variable in yourLambda. Furthermoreapplicationsshould do the opposite ofabstractions.Lambdato build an application. There are no lambdas in your description of what you want to do: "given a term N and a list of terms (X1,...,Xn) return N(X1,...,Xn)". Usually there's aTermconstructor for application.