Esempio n. 1
0
 def f(x: Type):
     return match(x)({
         TypePattern('T'):
             lambda T:
                 T,
         TypePattern('int(*)()'):
             lambda:
                 Type('bool'),
     })
Esempio 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,
     })
Esempio 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
     })
Esempio 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'),
     })
Esempio 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
Esempio 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,
     },
     {})
Esempio 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,
     })
Esempio 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],
     })
Esempio 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,
     })
Esempio 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
Esempio 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,
     })
Esempio 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'),
                 }),
     })
Esempio 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,
     })
Esempio 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'),
     })
Esempio n. 15
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('error'):
         lambda error: Type('T*', T=error),
     })
Esempio n. 16
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('error'): lambda error: 15,
     })
Esempio 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,
     })
Esempio 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,
     })
Esempio 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.
     })
Esempio 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,
     })
Esempio n. 21
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('value'): lambda value: 15,
     })
Esempio 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,
     })
Esempio n. 23
0
 def f(b: bool):
     return match(Type('int'))({
         TypePattern('type'):
         lambda type: Type('T*', T=type),
     })