What is a “First Class” type?

后端 未结 3 1611
故里飘歌
故里飘歌 2020-12-24 06:56

What does it mean for a type T to be a \"First Class\" type?

3条回答
  •  臣服心动
    2020-12-24 07:42

    The use of "T" make it sound like maybe someone was speaking about the state of generics in Java (they get erased, meaning that while you can check if something is a List at runtime, you can't check if it's a List of Integer).

    However, there are also "first class types," meaning that types themselves (not just instances of them) can show up anywhere, like as the value of an expression. For instance, code snippets like

    someType s = new someType();
    new typeOf(s); // makes a new instance of someType
    

    But you don't see that in the wild much, since if your types depend on a value, type-checking requires more computation, and if you allow types to depend on any value, then checking becomes undecidable.

提交回复
热议问题