Exemplo n.º 1
0
 def f(x: Type):
     return match(x)({
         TypePattern('T'):
             lambda T:
                 T,
         TypePattern('int(*)()'):
             lambda:
                 Type('bool'),
     })
Exemplo n.º 2
0
 def f(y: Type):
     return match(Type('int*'), y)({
         TypePattern('T', 'U'):
             lambda T, U:
                 False,
         TypePattern('T*', 'U*'):
             lambda T, U:
                 True,
     })
Exemplo n.º 3
0
 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
     })
Exemplo n.º 4
0
 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'),
     })
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 def f(x: Type):
     return match(x)({  # error: Malformed match\(...\)\({...}\)
         TypePattern('T(*)(U)'):
             lambda T, U:
                 Type('double'),
         TypePattern('int(*)(T)'):
             lambda T:
                 T,
     },
     {})
Exemplo n.º 7
0
 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,
     })
Exemplo n.º 8
0
 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],
     })
Exemplo n.º 9
0
 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,
     })
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 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,
     })
Exemplo n.º 12
0
 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'),
                 }),
     })
Exemplo n.º 13
0
 def f(x: Type):
     return match()({  # error: Found match\(\) with no arguments; it must have at least 1 argument.
         TypePattern('T'):
             lambda T:
                 T,
     })
Exemplo n.º 14
0
 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'),
     })
Exemplo n.º 15
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('error'):
         lambda error: Type('T*', T=error),
     })
Exemplo n.º 16
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('error'): lambda error: 15,
     })
Exemplo n.º 17
0
 def f(x: Type):
     return match(x)({
         TypePattern(x):  # error: The non-keyword arguments of TypePattern must be string literals.
             lambda T:
                 T,
     })
Exemplo n.º 18
0
 def f(x: Type):
     return match(x)({
         TypePattern():  # error: Found TypePattern with no arguments, but the first argument is required.
             lambda T:
                 T,
     })
Exemplo n.º 19
0
 def f(x: Type):
     return match(x)({
         TypePattern('T'):
             Type('int'),  # error: All values in the dict used in match\(...\)\({...}\) must be lambdas.
     })
Exemplo n.º 20
0
 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,
     })
Exemplo n.º 21
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('value'): lambda value: 15,
     })
Exemplo n.º 22
0
 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,
     })
Exemplo n.º 23
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('type'):
         lambda type: Type('T*', T=type),
     })