Typed Tuples in Cat version 0.18.1
I recently made a new release of Cat. This version has better type handling for recursive functions, more tests and some bug fixes. What is particularly interesting though is the addition of a new experimental primitive tenatively called “unpush”.
With the introduction of ”unpush” Cat 0.18.1 now can implement fully typed tuples. The method is quite unconventional because “unpush” takes ordinary functions, that don’t consume anything, and deconstructs them. In other words “unpush” has type “(( -> ‘A ‘b) -> ( -> ‘A) ‘b)”. By deconstructing these functions, we can get at the values contained within them. In most cases “unpush” is able to simply examine the contents of a function and extract the last instruction. In degenerate cases (like [1 dup]), the function must be first evaluated to find the top value. This is inefficient, but being a rare case we don’t care so much.
In practice this means that “unpush” behaves like “uncons” in Joy:
[1 2 3] unpush => [1 2] 3
So why not say it is precisely the same thing as “uncons”? Well there is a limitation, we can not add or remove items from a tuple dynamically, otherwise the type would become unknown until run-time. This is why I will still be leaving a distinction between a list and a tuple in the language. This could actually turn out to be the foundation for a strongly-typed object system in Cat which I will explore in later posts.