jspahrsummers / adt

Algebraic data types for Python (experimental, not actively maintained)
MIT License
172 stars 14 forks source link

sealed classes #45

Open adsharma opened 3 years ago

adsharma commented 3 years ago

There is some discussion on typing-sig about sealed classes here: https://mail.python.org/archives/list/typing-sig@python.org/thread/QSCT2N4RFPRQN2U7NIX6VCNVNDHGO22U/

Perhaps you can chime in with your thoughts as the author of this library.

@sealed
class Tree:
    EMPTY: None
    LEAF: Leaf
    NODE: Node

@dataclass  
class Leaf:
   data: int

@dataclass
class Node:
   left: Tree
   right: Tree  

would be nice. Other python libraries with similar functionality linked from here:

https://www.reddit.com/r/Python/comments/ipqqca/sum_types_discriminated_unions_for_python/

is pretty nice syntactically.