Question

I've been reading a bit about algorithms for evaluating lambda calculus (not parsing but just evaluating after is parsed), but so far all of them seem the kind of method you'd use with a pen and paper. I'd like to write my own lambda calculus evaluator in C# from scratch and would like to know how an actual program would do this.

Since lambda expressions are a superset of lambda calculus, I'd like to know how the lambda calculus subset of the lambda expressions are evaluated (don't care about binary operations or casting, etc.).

I already have my classes but I'm not sure how to go from here to evaluating:

public enum TermType { Variable, Application, Abstraction };

public abstract class LambdaTerm
{
    public readonly TermType TermType;

    protected LambdaTerm(TermType termType)
    {
        TermType = termType;
    }
}

public class LambdaVariable : LambdaTerm
{
    public string Name;
    public LambdaVariable() : base(TermType.Variable) { }
}

public class LambdaApplication : LambdaTerm
{
    public LambdaTerm Function;
    public LambdaTerm Parameter;
    public LambdaApplication() : base(TermType.Application) { }
}

public class LambdaAbstraction : LambdaTerm
{
    public string ArgumentName;
    public LambdaTerm Body;
    public LambdaAbstraction() : base(TermType.Abstraction) { }
}
Was it helpful?

Solution

Lambda expressions are not related to lambda calculus. The notation is similar, the semantics - completely different.

In fact, C# lambda expressions are just shorter forms of function. A chain of lambdas is in fact a chain of methods. What happens to it, depends on the context.

Instead of searching for analogies, just write a standard lambda calculus interpreter, following the semantic rules. This should be easy academic level task.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top