2 ms·
> I don't know what you mean by "fully exploit", If the return type of one of your overloads is itself a generic type, you can't represent that in the type of
by naasking 11y ago
> I don't know what you mean by "fully exploit",
If the return type of one of your overloads is itself a generic type, you can't represent that in the type of the method. Consider the IntBoolFactory from the paper, and then add two operations for lambda abstraction and function application:
public Exp lambda(Exp=>Exp body);
public Exp apply(Exp lambda, Exp arg);
Where Exp=>Exp represents a Java lambda taking an Exp and returnin an Exp. Notice how the type of the lambda and its argument must now be dynamically type checked to ensure that 'arg' has the same type as the parameter for the lambda. With higher kinded types, you could write something like this instead:
public <T0, T1> Exp lambda(Exp<T0>=>Exp<T1> body);
public <T0, T1> Exp<T1> apply(Exp<T0,T1> lambda, Exp<T0> arg);
And now everything is statically type checked by the Java compiler. Without higher kinded types, you gain extensibility in every direction using object algebras, but you lose some type checking.
- naasking 11y agoThat actually should read: public <T0, T1> Exp<T0, T1> lambda(Exp<T0>=>Exp<T1> body) But you get the idea.