Why have lower bounds on generics?
blog.jez.io·4d
🗂️Type Indexing
Preview
Report Post

What’s the point of lower bounds on generic types? For a while, I took for granted that you may as well have lower bounds if you have upper bounds, but that otherwise they’re mostly for academic symmetry, not something practical. After looking further, this is the best answer I can come up with:

Lower bounds expand the list of ways to create a value of that type (like how upper bounds expand the list of things to do with a value of that type).

Lower bounds are similar to union types in the same way that upper bounds are similar to intersection types. Thus, if a language has union+intersection types, it almost doesn’t need bounds at all.

Lower bounds allow for richer subtyping relationships than union types, while being more verbose in some cases.

Lower bou…

Similar Posts

Loading similar posts...