Ejemplo n.º 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));
        }
    }
Ejemplo n.º 2
0
    public override int CompareTo(SemanticType other)
    {
        // any functional type is greater than any
        // atomic type.
        if (other is AtomicType)
        {
            return(1);
        }

        FunctionalType that = other as FunctionalType;

        // if the arities of these semantic types are
        // unequal, the higher arity is greater.
        if (this.Input.Length > that.Input.Length)
        {
            return(1);
        }

        if (this.Input.Length < that.Input.Length)
        {
            return(-1);
        }

        for (int i = 0; i < Input.Length; i++)
        {
            int inputComparison = Input[i].CompareTo(that.Input[i]);
            if (inputComparison < 0)
            {
                return(-1);
            }

            if (inputComparison > 0)
            {
                return(1);
            }
        }

        var outputComparison = Output.CompareTo(that.Output);

        if (outputComparison < 0)
        {
            return(-1);
        }

        if (outputComparison > 0)
        {
            return(1);
        }

        return(0);
    }
 public void SetFunctionalButton(FunctionalType type)
 {
     switch(type)
     {
         case FunctionalType.New:
             _functionalButton.Text = "New";
             _functionalButton.Image = Properties.Resources.ios7_plus_outline;
             _functionalButton.Visible = true;
             break;
         case FunctionalType.Edit:
             _functionalButton.Text = "Edit";
             _functionalButton.Image = Properties.Resources.edit;
             _functionalButton.Visible = true;
             break;
         case FunctionalType.Hide:
             _functionalButton.Visible = false;
             break;
     }
     flowLayoutPanel.AutoScrollPosition = new Point(flowLayoutPanel.HorizontalScroll.Maximum, 0);
 }
Ejemplo n.º 4
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));
    }
Ejemplo n.º 5
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));
    }
Ejemplo n.º 6
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));
    }