Open LPTK opened 2 years ago
I no longer think it's a good idea to infer self types (or receiver refinements, for that matter), but we could still use partially-specified self types with class-level type variables to achieve simple extensible programming as in @andongfan's project:
class Base {
self: { eval: 'a -> int } // used when typing methods below
// Note that 'a is quantified at the level of the class instance
...
fun eval: (Lit | Add('a, 'a)) -> int
= ...
}
I think this actually helps to clarify the approach, and could be presented as the desugaring of the syntax we show in the SRC extended abstract.
To avoid confusion, we may want to capitalize class-level type variables, as in fun eval: (Lit | Add('A, 'A)) -> int
, otherwise one could think the function is polymorphic in it.
Example: