There seems to be one limitation to this approach. It cannot capture the this type as an HKT.
Suppose class A is a parent of class B, and A provides common methods for its children. We can return the this type from the methods of A to enable us chain the methods with those in its sub classes. But if A has a type parameter, say A<'a>, we cannot pass that parameter to the this type as A<'b>.
Using the registry approach to HKTs, I was able to do that. It's useful for modelling OOP libraries like joi.
I still like this approach, it's simpler.
Edit
It's actually possible to pass a new type argument to a sub class from its super class. It requires defining a separate HKT for each class, then passing the HKT of the sub class to its super class.
There seems to be one limitation to this approach. It cannot capture the
this
type as an HKT.Suppose class A is a parent of class B, and A provides common methods for its children. We can return the
this
type from the methods of A to enable us chain the methods with those in its sub classes. But if A has a type parameter, sayA<'a>
, we cannot pass that parameter to thethis
type asA<'b>
.Using the registry approach to HKTs, I was able to do that. It's useful for modelling OOP libraries like joi.
I still like this approach, it's simpler.
Edit
It's actually possible to pass a new type argument to a sub class from its super class. It requires defining a separate HKT for each class, then passing the HKT of the sub class to its super class.
Not sure I understand would you mind making a simple example?