Untyped lambda calculus in C #

I am trying to implement the original lambda calculus in C #, but I have some problems with its implementation, since in the end I always get asked for objects.

I would like something that would allow me, for example, to identify a few basic logical combinators, such as

I = Lambda x. x
M = Lambda x. x(x)

but C # seems to work under the assumption that in the end it will get the object. I tried to define them differently, for example

using lambda = Func<Object, Object>;
using lambda = Func<Func<Object, Object>, Func<Object, Object>>;
using lambda = Func<Func, Func>;

etc., but those that do not obey the syntax or are incompatible with

lambda I = x => x;
lambda M = x => x(x);

I tried using a delegate

public delegate object lambda(Object o);

static object i(object o)
{
    return o;
}

static object m(object o)
{
    return ((lambda)o)(o);
}

But in the end, for any actual use of these functions, you will still need an argument at the end of the line, and a dummy argument, for example

m(m(i('')));

just result in a startup error.

- ?

. :

lambda i(lambda x)
{
    print("i");
    return x;
}

lambda m(lambda x)
{
    print("m");
    return x(x);
}

(m (m)) (i) - m (m) , m (m) "m", (m (m)) ( i), "m" ( , , ).

+4

Source: https://habr.com/ru/post/1681745/


All Articles