https://kotlinlang.org logo
#announcements
Title
# announcements
r

raulraja

04/04/2017, 2:07 PM
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

voddan

04/04/2017, 2:23 PM
How is it different from generics?
interface X<F> {fun x(): F}
r

raulraja

04/04/2017, 2:43 PM
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

jaspersmit

04/04/2017, 2:46 PM
Is this what typedef can do in c++?
v

voddan

04/04/2017, 2:46 PM
@raulraja thanks, I'll read it!
r

raulraja

04/04/2017, 2:46 PM
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

voddan

04/04/2017, 2:47 PM
Arity is a totally different issue, IMHO
r

raulraja

04/04/2017, 2:48 PM
@jasper I'm not familiar with typedef
j

jaspersmit

04/04/2017, 2:49 PM
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

raulraja

04/04/2017, 2:51 PM
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.