Beispiel #1
0
    // @Note we might make these constructors their own
    // classes if it's easier to think about making
    // Words or Phrases. But I wanted to consolidate a bit.

    // This constructor is a 'word' constructor.
    // It makes a constant or a variable by itself.
    public Expression(Atom head)
    {
        Type  = head.Type;
        Head  = head;
        Depth = 1;

        // we check if the head expression has an atomic type.
        // if it does, then we just initialize an empty array
        // since this expression doesn't take any arguments.
        if (Head.Type is AtomicType)
        {
            Args    = new Argument[0];
            NumArgs = 0;
            return;
        }

        // we're going to populate the argument array with
        // empty slots that are typed according to the
        // semantic type of the functional head expression.
        FunctionalType fType    = head.Type as FunctionalType;
        int            fNumArgs = fType.GetNumArgs();

        Args    = new Argument[fNumArgs];
        NumArgs = fNumArgs;
        for (int i = 0; i < fNumArgs; i++)
        {
            Args[i] = new Empty(fType.GetInput(i));
        }
    }
Beispiel #2
0
    public static SemanticType Push(SemanticType t, SemanticType ts)
    {
        if (ts is AtomicType)
        {
            return(new FunctionalType(new SemanticType[] { t }, (AtomicType)ts));
        }

        FunctionalType fts       = ts as FunctionalType;
        var            numInputs = fts.GetNumArgs();
        var            newInputs = new SemanticType[numInputs + 1];

        newInputs[0] = t;

        for (int i = 0; i < numInputs; i++)
        {
            newInputs[i + 1] = fts.GetInput(i);
        }

        return(new FunctionalType(newInputs, fts.Output));
    }
Beispiel #3
0
    // if the input type is i1, ..., in -> o,
    // and the lift type is l, then
    // the geach type is (l -> i1), ..., (l -> in), l -> o
    public static SemanticType Geach(SemanticType lift, SemanticType input)
    {
        if (input is AtomicType)
        {
            return(new FunctionalType(new SemanticType[] { lift }, (AtomicType)input));
        }

        FunctionalType ft        = input as FunctionalType;
        var            numInputs = ft.GetNumArgs();

        SemanticType[] newInputs = new SemanticType[numInputs + 1];

        for (int i = 0; i < numInputs; i++)
        {
            newInputs[i] = Push(lift, ft.GetInput(i));
        }

        newInputs[numInputs] = lift;

        return(new FunctionalType(newInputs, ft.Output));
    }
Beispiel #4
0
    public override bool Equals(Object o)
    {
        if (o.GetType() != typeof(FunctionalType))
        {
            return(false);
        }

        FunctionalType that = (FunctionalType)o;

        if (Input.Length != that.GetNumArgs())
        {
            return(false);
        }

        for (int i = 0; i < Input.Length; i++)
        {
            if (Input[i] != that.GetInput(i))
            {
                return(false);
            }
        }

        return(Output.Equals(that.Output));
    }