0
lorentz
2y

In type systems without variadic generics, tuples should be defined as a type-level conslist:

Tuple<int, Tuple<string, Tuple<bool, TupleEnd>>>

Consider the possibilities, even just in a regular type system, then consider how much more is possible with dependent types!

Comments
  • 0
    In Python, namedtuples can be used.

    https://docs.python.org/3/library/...
  • 0
    @IntrusionCM Python prefers to generate errors in production rather than in real time while the code is written. Enabling the type system to recursively "walk" a tuple is mainly beneficial for static polymorphism in type-safe languages.
  • 0
    That looks messy.. and how would you allow nesting tuples with this?

    E.g. typescript has its own syntax like [string, number] instead of variadic generics
  • 0
    @devRancid You would have syntax sugar for building these obviously, and you could also display them with that custom syntax in errors.

    Nesting tuples is easy because the first parameter is always the element type while the second is the tail type. It works exactly like a conslist, nesting conslists isn't an issue.

    As for Typescript, you can use array comprehension syntax on types as well which works basically like variadic generics.

    In languages without variadic generics a function can be polymorphic over (int, int) and (string, string) but not (int, int) and (int, int, string). This is literally impossible without variadic generics.
Add Comment