has there been any discussions regarding support f...
# announcements
r
has there been any discussions regarding support for some kind of dependent/abstract types in Kotlin?. something like ...
Copy code
interface X {
  typealias F
  fun x() : F
}

class Y : X {
  typealias F = String
  fun x() : String = "hello dependent types!"
}
v
How is it different from generics?
interface X<F> {fun x(): F}
r
among other things help parametrization not to explode quadratically as in regular generics and also helps with variance. there are several posts in the Scala community around this concept and differences. For example http://www.artima.com/weblogs/viewpost.jsp?thread=270195.
j
Is this what typedef can do in c++?
v
@raulraja thanks, I'll read it!
r
Also useful to encode type level computations and build things such as HList and other that can help abstract over arity. It's currently impossible in Kotlin to abstract over arity AFAIK resulting in boilerplate like this https://github.com/FineCinnamon/Katz/blob/master/katz/src/main/kotlin/katz/typeclasses/Applicative.kt#L44
v
Arity is a totally different issue, IMHO
r
@jasper I'm not familiar with typedef
j
So you can do Type<Int>::Editor which is a typedef to an IntEditor
i needed this in kotlin but all you can do is have a super class Editor which you have to downcast yourself to IntEditor
so what i basically needed was a getEditor<T>() function which infers the correct editor type
r
yes, the current higher kinds emulation in the project linked above forces you to downcast based on evidence to prove you are talking about a type constructor in a similar context. The sad part is that there is no warning because the compiler can see the cast is safe.