Beispiel #1
0
    def test_parse_variable_type(self):
        assert qtype.is_variable(self.parser.parse_type('?a'))

        fun = self.parser.parse_type('?a->?a')
        assert fun.args[0] == fun.args[1]

        fun = self.parser.parse_type('?a->?b')
        assert fun.args[0] != fun.args[1]

        fun2 = self.parser.parse_type('?a->?b')
        assert fun.args[0] != fun2.args[0]
        assert fun.args[1] != fun2.args[1]
Beispiel #2
0
    def build_combination(self, operator, operand):
        if qtype.is_variable(operator.qtype):
            operator = operator.substitute_type(qtype.qfun(operand.qtype, qtype.qvar()), operator.qtype)

        if operator.qtype.name != "fun":
            raise TypeError("operators must be functions")

        unifier = qtype_unifier.TypeUnifier()
        unifier.unify(operator.qtype.args[0], operand.qtype)
        for key, value in unifier.get_substitutions().iteritems():
            operator = operator.substitute_type(value, key)
            operand = operand.substitute_type(value, key)

        operator, operand = unify_types([operator, operand])

        if operator.qtype.args[0] != operand.qtype:
            raise TypeError("operand type must match operator argument type")

        return qterm.Combination(operator, operand)
Beispiel #3
0
 def test_parse_untyped_variable(self):
     var = self.parser.parse('var')
     assert var.name == 'var'
     assert qtype.is_variable(var.qtype)