Search code examples
c#functional-programmingcombinators

Is A Class Member Variable Bound Or Free (In Terms Of Combinators)?


While I realize I'm not being very rigorous, I'm pretty sure the definition of a combinator in simple terms is simply a function with no free variables. For example,

f(x,y) = x + y

would be a combinator and

f(x,y) = x * 2

would not be because y would be free.

So given that understanding would a member variable in a class definition be considered "free"? I'm guessing it would but I wanted to check my assumption. Code like this C# example:

namespace ConsoleApplication1
{
    class BoundOrFree
    {
        private int _i = 0;

        public int f(int x, int y)
        {
            return x + y + _i;
        }
    }
}

In the BoundOrFree.f member function is _i free? Would f therefore not be a combinator? I'm assuming the answer to both of those questions would be yes but I wanted to confirm my assumption.


Solution

  • would not be because y would be free

    you misinterpret the "free" term in this case. Free variable is the one that was captured from the outer scope (via a closure). So f(x,y) = x * 2 is a combinator.

    Answering your question

    In the BoundOrFree.f member function is _i free? Would f therefore not be a combinator?

    the BoundOrFree::f function is not a combinator, since it uses variables other than its only arguments.