4 ms·
Python's pattern matching is not the same as Ocaml's. It's a statement, not an expression. But I like your line of thinking. Create a variant of python with ML
by adsharma 5y ago
Python's pattern matching is not the same as Ocaml's. It's a statement, not an expression. But I like your line of thinking. Create a variant of python with ML like features without sacrificing compatibility too much.
An effort in this direction is a transpiler I'm working on. So far it sticks to a strict subset of python3. But I'm open to incorporating ML like features in an incompatible way if there is a compelling argument.
By sticking to a statically typed subset we've already given up some compatibility.
- nickmain 5y agoIf you want to use OCaml-like GADTs and pattern matching in Python then there is the Haxe -> Python route. The Haxe compiler is actually written in OCaml and its type system is influenced by it.
- adsharma 5y agoThanks for the link. I'm thinking along the same lines and might derive some inspiration from Haxe on how to evolve python syntax to support features like GADT and FP that can be easily transpiled to other languages. It looks like Haxe was designed from day 1 to be transpiler friendly, whereas I'm trying to leverage python's popularity and language ecosystem to achieve similar goals. Sticking to a strict subset of python has the advantage that all the scripts are directly executable by the python interpreter. If we add some features (say implemented pattern matching similar to OCaml), we lose that. Perhaps some macros/library features can bridge that gap. Or over time, python evolves to be more like OCaml.
- adenozine 5y agoI mean, obviously you're right. I guess I just meant that it's good enough for what I'm doing in Python. People don't write verified provers for deep numerical projects in Python, they'd use Ocaml. For digging through a little sqlite collection, parsing through csv files and correlating a few simple features in dataframes, python works fine and the pattern matching that we'll be getting will make it easier to write THAT sort of code. I don't see Python growing very much more functionally. There's two decades of resisting FP with much vigor, and I expect another two decades of fighting about what little FP has grown into Python thus far. I'd love to see your transpiler work! It sounds pretty cool. I keep an eye on mys-lang (@github/mys-lang/mys) and mypyc, to see what's going on in that realm of Python. Compatibility is a double-edged sword, as I'm sure you realize.
- adsharma 5y agoThanks for the link. I wasn't aware of mys. The project I'm working on is called py2many https://news.ycombinator.com/item?id=27032399 https://news.ycombinator.com/item?id=27032399