I'm trying to write something that reads Lambda expressions and outputs a beta reduced version. Lambdas will be typed as follows : \variable -> expression and applications will be of the form (expression) (expression). So if '\' is found at the beginning of the string it knows to process a Lambda and if '(' is found it knows to process an application.
I have a type for Lambda Expressions defined:
data Expression = Variable String
| Lambda Expression Expression
| Apply Expression Expression
Here's my first attempt at writing a function for reading the input
processInput :: String -> Expression
processInput ('\':input) = processLambda input
processInput ('(':input) = processApply input
processInput str = Variable str
When I try to load this function I get
lexical error in string/character literal at ':'
So I tried using guards instead:
processInput input
| head input == '\' = processLambda (tail input)
| head input == '(' = processApply (tail input)
| otherwise = Variable input
But got
lexical error in string/character literal at character ' '
I have no idea what's wrong with either of these functions.