3 ms·
Python has some basic pattern matching. ADTs are alright, but if you notice that MLs implement them by tagged unions, then really this is a request for syntax a
by lidHanteyk 7y ago
Python has some basic pattern matching. ADTs are alright, but if you notice that MLs implement them by tagged unions, then really this is a request for syntax and ergonomics, not semantics.
Python is untyped. This fundamental separation between Python and Haskell is non-trivial, and can't be papered over. Your complaints about exhaustiveness, field existence, and case analysis are all ultimately about the fact that Python's type system is open for modification, while Haskell's is closed; in Haskell, we can put our foot down and insist that whatever we see is an instance of something that we've heard of, but in Python, this is simply not possible.
I agree, when it comes to Python's moves. I am about ready to leave Python 2, but I'm not going to Python 3.
- oisdk 7y agoWhile I am all for stronger type systems, I don't agree that you need it to do sum types. We can already do one half of ADTs (classes ~= product types), I just want the other half! In my mind, the syntax would be something like this: sum_class Tree: case Leaf: pass case Node: data: Any left: Tree right: Tree def size(tree): case(Tree) tree of: Leaf: return 0 Node(_, left, right): return 1 + size(left) + size(right) A combination of data classes and pattern matching.