Currently, we model module/class themselves (as opposed to instances) as singleton(Klass), whereas the Module/Class classes can only represent the module/class of untyped.
I suggest combining those two by giving Module and Class a type variable representing their instances. For example, Class[String] (and Module[String] too to under covariance) is equivlaent to singleton(String).
For backward compatibility, singleton(I) can be a alternate (read: legacy) syntax for Module[I].
The immediate benefit is Class[I] RBS finally able to write def new: (…) -> I and def allocate: () -> I (rather than expecting type checkers to infer from singleton(I)).
Speaking of singleton(I) —
|
| `singleton(` _class-name_ `)` (Class singleton type) |
[I < Bound] … singleton(I) is invalid. (Update: this is
#558)
[I < singleton(Bound)] -> I works the limitation around, but what if
I has other duties?
# Modules can’t inherit Classes, so I’m stuck with this design.
class MyClassWrapper[I < MyObject] < MyComponent
def initialize: (singleton(I) klass) -> void #FIXME: Class[I] when
def customized_new: (*args) -> I
end
This is also how Java does it (as early as their type args were born).
Currently, we model module/class themselves (as opposed to
instances) assingleton(Klass), whereas theModule/Classclasses can only represent the module/class ofuntyped.I suggest combining those two by giving
ModuleandClassa type variable representing their instances. For example,Class[String](andModule[String]too to under covariance) is equivlaent tosingleton(String).For backward compatibility,
singleton(I)can be a alternate (read: legacy) syntax forModule[I].The immediate benefit is
Class[I]RBS finally able to writedef new: (…) -> Ianddef allocate: () -> I(rather than expecting type checkers to infer fromsingleton(I)).Speaking of
singleton(I)—rbs/docs/syntax.md
Line 9 in 6e5a289
[I < Bound] … singleton(I)is invalid. (Update: this is #558)[I < singleton(Bound)] -> Iworks the limitation around, but what ifIhas other duties?This is also how Java does it (as early as their type args were born).