def test_function_signature_with_type_variables(self): function = types.Function.for_multiple_inputs( [types.UnconstrainedType(), types.UnconstrainedType()], types.UnconstrainedType(), ) self.assertEqual(function.as_signature(codegen.Module()), "a -> b -> c")
def test_type_variables_complex(self): r1 = types.Record() r1.add_field("foo") r1.add_field("bar") r2 = types.Record() r2.add_field("baz") function = types.Function.for_multiple_inputs( [r1, r2], types.UnconstrainedType()) self.assertEqual( function.as_signature(codegen.Module()), "{ a | bar : b, foo : c } -> { d | baz : e } -> f", )
def test_empty_record_signature_in_function(self): function = types.Function(types.Record(), types.UnconstrainedType()) self.assertEqual(function.as_signature(codegen.Module()), "a -> b")
def test_unconstrained_signature(self): u = types.UnconstrainedType() self.assertEqual(u.as_signature(codegen.Module()), "a")
def __init__(self): self._type = types.UnconstrainedType()
def type(self): return types.UnconstrainedType()
def __init__(self, type_obj=None): if type_obj is None: type_obj = types.UnconstrainedType() self._type = type_obj
return self def sub_expressions(self): yield self.left yield self.right def constrain_type(self, type_obj, from_ftl_source=None): self.left.constrain_type( type_obj.constrain(resolve_type(operand_type))) self.right.constrain_type( type_obj.constrain(resolve_type(operand_type))) return Op Equals = infix_operator("==", "Bool", types.UnconstrainedType()) Add = infix_operator("+", "Number", "Number") class RecordUpdate(Bracketing, Expression): def __init__(self, var, **updates): assert isinstance( var.type, types.Record), "isinstance({0}, types.Record)".format(var.type) assert isinstance( var, VariableReference), "isinstance({0}, VariableReference)".format( var) assert ( var.module_name is None ), "Record update syntax does not allow qualified name like {0}.{1}".format(