November 21, 2013
I have a lot of ideas for programming languages and type systems. Here are a few I’ve been thinking about today:
- A programming language where mutable types are uniqueness types. In other words, you can only mutate an object if you have the only reference to it. Why this restriction? Because all objects are automatically thread-safe! And you get almost all the benefits of immutability, but it’s not nearly as restrictive as a pure functional programming language.
- (This is not really a serious idea.) A programming language with no data type for strings. Why? Far too often, strings are used as an unstructured way to represent structured data: file system paths, SQL queries, XML, HTML, regular expressions, etc. Representing structured data as strings sidesteps the type system, and doing so can lead to injection attacks. This is called “stringly-typed” programming.
- A type system that fits into a lattice, where order is given by the subtyping relation. The concepts of subtyping, inheritance, interfaces, and union types are all unified in this system. Taking the supremum of types
Yis equivalent to the union type
X | Y. Taking the infimum of
Yis equivalent to the type of objects that implement interfaces
- Tracing garbage collection is a cool way to manage memory, but it can cause random pauses at runtime (which may be unacceptable for real-time applications). Reference counting is an intriguing alternative, but it fails to reclaim cyclic data structures. Forget about both for a second. Let’s say you have no access to a system memory heap—and you have no pointers or references either. Instead, you can create “memory heap objects”, and then ask them for memory when you need it. When you ask for some memory, instead of a pointer to it, you get a “key” that indexes the memory heap like a hash table. Now—the memory heap objects are reference-counted, and are never cyclic (even if the structures they allocate are cyclic). When the memory heap is released (automatically, due to reference counting), anything it allocated is released as well. No unpredictable garbage collection stops, no cycles, no memory leaks.
- Using monads to chain asynchronous events, such as futures. Maybe this can be combined with #4 to make a cutting-edge web framework.
- Crazy type systems. Type systems that model quantum behavior. Type systems that model latency in networks. Type systems that model security access levels for web apps. Type systems that model physical units. Type systems that model probability distributions. Type systems that model relational data (as in SQL). Type systems that model proofs. Each of these might make an interesting programming language.