r/programming • • May 21 '20

Java programming language celebrates 25 years

https://www.infoworld.com/article/3544229/java-programming-language-celebrates-25-years.html
95 Upvotes

73 comments sorted by

View all comments

Show parent comments

2

u/flatfinger May 21 '20

What do you mean "higher kinded types"? The .NET framework, and languages targeting it, use reified generics but also support covariant and contravariant generic interfaces.

2

u/DetriusXii May 21 '20

Higher kinded types are generic types that can box other types. Haskell and Scala support higher kinded types whereas .NET only support concrete types. Instead of only being able to pass a function void doSomething<A>(List<A> list) into a function, in Haskell and Scala, a function can be declared as void doSomething<M<_>, A>(M<A> list) where M can be any type of container, including a List<_>.

1

u/kprotty May 21 '20

If I understand that definition of HKT correctly, then could Ziglang be considered as one with reified generics without type erasure?

fn doSomething(comptime M: var, comptime A: type, list: M(A)) void {}

1

u/DetriusXii May 22 '20

If Zig allows that, then you have higher kinded types. I'm not fully sure that zig's types are reified from the examples provided. Are you able to perform a cast of a function parameter into a generic type? C# allows that. Java does not. C# allows bool compare<Q>(object o) { return o instanceof Q; }

→ More replies (0)