elizarov
06/27/2018, 6:43 AMfun <T> foo(a: T): List<T>
(the type of foo
in Haskell terms would be forall t. t -> List t
), but you cannot directly capture such a functional type in a plain variable. You’ll have to always capture both foo
and T
with another generic function like fun <T> bar(a: T) = foo(foo(a))
or with a generic class like class A<T> { fun bar(a: T) = foo(a) }
elizarov
06/27/2018, 6:44 AMforall
quantifier in Kotlin have to alway be on the “top level” of the type.elizarov
06/27/2018, 8:02 AMList (forall t. t -> t)
. In order to model such a type in Kotlin you’ll have to define an interface with generic function interface IdFun { fun <T> id(a: T): T }
and then List<IdFun>
would be equivalent to List (forall t. t -> t)
pakoito
06/27/2018, 9:42 AMjacob
06/27/2018, 11:32 AM