def f(x: Type): return match(x)({ TypePattern('T'): lambda T: T, TypePattern('int(*)()'): lambda: Type('bool'), })
def f(y: Type): return match(Type('int*'), y)({ TypePattern('T', 'U'): lambda T, U: False, TypePattern('T*', 'U*'): lambda T, U: True, })
def f(x: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: Type('double'), # note: A previous lambda returning a Type was here. TypePattern('int(*)(T)'): lambda T: True, # error: All lambdas in a match\(...\)\({...}\) expression should return the same type, but this lambda returns a bool while a previous lambda in this match expression returns a Type })
def f(x: Type): return match(x)({ TypePattern('T'): # note: A previous specialization that specializes nothing was here lambda T: Type('double'), TypePattern('U'): # error: Found multiple specializations that specialize nothing lambda U: Type('double'), })
def f(x: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: Type('double'), TypePattern('int(*)(T)'): lambda T: T, }, wrong_arg=True) # error: Keyword arguments are not allowed in match
def f(x: Type): return match(x)({ # error: Malformed match\(...\)\({...}\) TypePattern('T(*)(U)'): lambda T, U: Type('double'), TypePattern('int(*)(T)'): lambda T: T, }, {})
def f(x: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: 1, TypePattern('int(*)(T)'): lambda T: 2, TypePattern('float(*)(T)'): lambda T: 3, })
def f(x: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: [Type('double')], TypePattern('int(*)(T)'): lambda T: [T], TypePattern('float(*)(T)'): lambda T: [T], })
def f(x: Type, y: Type): return match(x)({ TypePattern('T(*)(U)'): lambda T, U: Type('double'), TypePattern('int(*)(T)'): lambda T: y, TypePattern('float(*)(T)'): lambda T: T, })
def f(x: Type): result = match(x)({ TypePattern('T(*)(U)'): lambda T, U: Type('double'), TypePattern('int(*)(T)'): lambda T: id(T), TypePattern('float(*)(T)'): lambda T: T, }) return result
def f(x: Type): return match(x, x)({ TypePattern('T', wrong_arg=x): # error: Keyword arguments in TypePattern are not supported yet. lambda T: T, })
def f(x: Type, y: Type): return match(x)({ TypePattern('T'): lambda T: y, TypePattern('T(*)(U)'): lambda T, U: match(T, U)({ TypePattern('int', 'V'): lambda V: y, TypePattern('float', 'V'): lambda V: Type('bool'), }), })
def f(x: Type): return match()({ # error: Found match\(\) with no arguments; it must have at least 1 argument. TypePattern('T'): lambda T: T, })
def f(x: Type): return match(x)({ TypePattern('Bar'): # note: The type patterns were defined here. lambda Baz: # error: The parameter Baz in the lambda does not appear in any type pattern. Type('double'), })
def f(b: bool): return match(Type('int'))({ TypePattern('error'): lambda error: Type('T*', T=error), })
def f(b: bool): return match(Type('int'))({ TypePattern('error'): lambda error: 15, })
def f(x: Type): return match(x)({ TypePattern(x): # error: The non-keyword arguments of TypePattern must be string literals. lambda T: T, })
def f(x: Type): return match(x)({ TypePattern(): # error: Found TypePattern with no arguments, but the first argument is required. lambda T: T, })
def f(x: Type): return match(x)({ TypePattern('T'): Type('int'), # error: All values in the dict used in match\(...\)\({...}\) must be lambdas. })
def f(x: Callable[[Type], Type]): return match(x)({ # error: All arguments passed to match must have type Type, but an argument with type \(Type\) -> Type was specified. TypePattern('T'): lambda T: T, })
def f(b: bool): return match(Type('int'))({ TypePattern('value'): lambda value: 15, })
def f(x: bool): return match(x)({ # error: All arguments passed to match must have type Type, but an argument with type bool was specified. TypePattern('T'): lambda T: T, })
def f(b: bool): return match(Type('int'))({ TypePattern('type'): lambda type: Type('T*', T=type), })