Skip to content

Instantly share code, notes, and snippets.

@jfdm
Created July 1, 2025 14:58
Show Gist options
  • Save jfdm/fbb1f88065ab97b3c8e57ef322b1720e to your computer and use it in GitHub Desktop.
Save jfdm/fbb1f88065ab97b3c8e57ef322b1720e to your computer and use it in GitHub Desktop.
Not Quite Four but that is not the point...
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))))
$ 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