Was writing the compiler in Python a good idea?
It’s been more than three years now since I started writing a compiler in Python. Looking back, did I choose the right language?
Newton is still under development. The above points are aspirational.
It’s been more than three years now since I started writing a compiler in Python. Looking back, did I choose the right language?
One way to think about Python is that it’s built up from progressively larger sublanguages, like the layers of an onion. Turns out we can peel off the top layer and still have something useful, maybe even more useful for some purposes.
AI makes it easier than ever before to produce code. It helps actual programmers produce more code in less time, and lets more people who are not trained programmers participate. But what does this mean for compiler writers and language designers?
Python is more than thirty years old at this point and has accumulated some cruft. New languages have the opportunity to improve on Python by omitting some of the features.
It is an enormous amount of work to design and implement a language the scale of Newton. Just learning the type theory takes years. I knew nights and weekends would not suffice, so the first thing I did was quit my job. Which raises the question, how am I financing this?
Newton’s type system takes a lot of ideas from Haskell and inherits many of the same concepts. One such concept is “skolems”. But what does that mean?
How does one encourage the use of immutable data structures
when the established idioms center on imperative for loops,
without creating a rift in the language?
I have been mulling over this question and think I found a good answer.
It turns out that pattern matching on Python-style tuples requires existential types. This is the second time I encounter them, so I figured it is a good opportunity to show how they arise in practise.
Python’s print function is difficult to type check because it takes an arbitrary number of arbitrary arguments. We cannot give it a fixed number of type parameters, like other polymorphic functions. Is it even possible to accomodate a function like this in a statically typed language? I think so.
I am now able to compile small but useful Newton programs that exercise the full feature set to Python! This is a major breakthrough because until now there was always something that would break when you tried something more complex.