Marc Knaup
10/18/2017, 7:30 PMinline fun <reified Value : Any> test1(): Value = TODO()
inline fun <reified Value : Any> test2(): List<Value> = TODO()
val test: List<Int> = test1()
In the example using test1() (accidentally instead of test2()) should raise an error because I cannot get the generic type of the List anyway.Ruckus
10/18/2017, 7:40 PMMax Russek
10/18/2017, 7:42 PMraulraja
10/18/2017, 7:43 PMList<Int> not List in higher kind position.Marc Knaup
10/18/2017, 7:54 PMtest1() behave differently for List<…>, does it?Marc Knaup
10/18/2017, 7:55 PMValue = Int - Int isn’t generic, is it? Or am I using the wrong term somewhere?Max Russek
10/18/2017, 7:59 PM*), or a generic type (i.e kind * -> *). You have to take all of them (both kinds * and * -> *)Ruckus
10/18/2017, 8:01 PMValue in your example is a generic type, which is required by reified). If you're saying you don't want Value to resolve to a type which in turn has a generic type, no it's not possible as far as I am aware. If you're saying you want different behavior if there is a generic parameter, you can use reflection.Marc Knaup
10/18/2017, 8:04 PMraulraja
10/18/2017, 8:05 PMtest1<List<Int>>() // Value is `List<Int>`
test2<Int>() // List<Int>
But yeah, you can't use a kind in that position. because of no HKTs. yet... https://github.com/Kotlin/KEEP/pull/87 😉raulraja
10/18/2017, 8:09 PMfun <F<_>, A, B> transform(fa: F<A>, f: (A) -> B): F<B> given Functor<F> = F.map(fa, f)
The you can use your polymorphic function to satisfy all types for a which a Functor instance exists:
transform(listOf(1), { it + 1 })
transform(Option(1), { it + 1 })
transform(Try(1), { it + 1 })Marc Knaup
10/18/2017, 8:29 PMdamian
10/18/2017, 8:44 PMPureReifiable to denote that a particular reified type parameter can be a generic type: https://github.com/JetBrains/kotlin/blob/master/core/builtins/src/kotlin/internal/InternalAnnotations.kt#L25
but it is internal 😕raulraja
10/18/2017, 9:56 PM@PureReifiable ?damian
10/18/2017, 9:58 PMarrayOf, emptyArray, arrayOfNulls