What are generic type aliases? Is it just any generic type, e.g. Iterator in Java?
What is the type of the compose function '|>' if it is not generic?
What are generic type aliases? Is it just any generic type, e.g. Iterator in Java?
What is the type of the compose function '|>' if it is not generic?
type FooOf<T> = Array<T> | { prop: T }
These are much more powerful than generics in languages like Java because they let you build an arbitrarily-tall tower of type abstractions. What I've found in practice is that at least when it comes to application code, these are rarely needed and cause more obfuscation than benefit.On the other hand, generic functions in TypeScript allow you to bind together the types of arguments and/or returned values:
function last<T>(arr: Array<T>): T {
return arr[arr.length - 1]
}
which I see as pretty essential. So my thinking is to allow the latter (as well as generic classes), but not the former (non-generic type aliases will still be available). There will also be some built-in generic types like promises (or some equivalent) and iterators.|> has special language-level status and works sort of like generics, but doesn't need to be implemented in terms of them (though it may end up that way just to simplify the compiler)
In application code, maybe; it seems to be more the kind of type-system feature that is useful in enabling more powerful libraries of abstractions than doing much for applications, as such, given the assumption of equivalent available libraries.
OTOH, while language expressive power isn't the only factor in what libraries are written in and for it, it is a factor.
1) I'm working in a TypeScript codebase at work right now where people are often struggling with the types, because one of our main libraries got way too complex with their generic aliases. It creates error messages that are impossible to follow, and it's become a real drag on productivity, even in a library. This is in contrast with other TypeScript projects I've worked on that used different libraries and did not face this problem.
2) Bagel is being intended as an application-focused language (not unlike Go in that way). Not that people couldn't or wouldn't write libraries in it, but the expectation is that the most fundamental and general constructs will come batteries-included.
Expressivity is a double-edged sword. I'm making a particular choice about how best to strike that balance for Bagel's intended use-cases, and I'm going to see how it pans out. It also isn't set in stone yet; I plan on doing some projects in Bagel before all is said and done, as a way of seeing how this stuff impacts projects in practice.
type Maybe<T> = Some<T> | Error
Not sure why you'd want to disallow that.