Created
July 1, 2025 14:58
-
-
Save jfdm/fbb1f88065ab97b3c8e57ef322b1720e to your computer and use it in GitHub Desktop.
Not Quite Four but that is not the point...
This file contains hidden or 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
from __future__ import annotations | |
from dataclasses import dataclass | |
@dataclass | |
class NonZero: | |
succ : Nat | |
Nat = NonZero | None | |
Zero = None | |
def add(x : Nat, y : Nat) -> Nat: | |
match x: | |
case None: | |
return y | |
case NonZero(succ): | |
return NonZero(add(succ,y)) | |
if __name__ == "__main__": | |
print(add(NonZero(NonZero(Zero)), NonZero(NonZero(Zero)))) |
This file contains hidden or 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
$ python3 Nat.py | |
NonZero(succ=NonZero(succ=NonZero(succ=NonZero(succ=None)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment