Skip to content
Discussion options

You must be logged in to vote

Yes, this is a place where the "set of runtime values" definition becomes problematic. The way I think of it is that a generic conceptually carries around not only its value, but a "tag" representing its type argument, which is erased at runtime ("type erasure" is a well-known concept in some other languages). We might represent it with <T> before the value. So your different [b] lists are to the type checker <A>[b] (of type list[A]) and <B>[b] (of type list[B]).

It follows that it is impossible to tell at runtime what the static type of a list object is, so any type narrowing (e.g., TypeIs) that purports to narrow the type of a list is inherently unsound.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@doeblerh
Comment options

@carljm
Comment options

carljm Nov 5, 2025
Collaborator

Answer selected by doeblerh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants