Created
April 18, 2024 07:36
-
-
Save mypy-play/5e61f50c5c61bf4c90b5e1403f2b6be1 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run the type checking with "mypy --strict foo.py" | |
class Add(tuple[int,int]): | |
pass | |
class Const(int): | |
pass | |
Expr = Add | Const | |
def my_eval(e : Expr) -> int: | |
match e: | |
case Add((a,b)): | |
return a + b | |
case Const(x): | |
return x | |
print(my_eval(Const(42))) | |
print(my_eval(Add((42,45)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment