Hey all. I'm new. I was fiddling around with generics and type inference using functional approaches, but I'm a little confused about type inference logic for second order functions.
Given
fun <E> firstOrderFnWithSecondOrderTypeInference() = { value: E -> value }
, attempting to
firstOrderFnWithSecondOrderTypeInference()(42)
gives me a type inference error:
Type inference failed: Not enough information to infer parameter E in fun <E> firstOrderFnWithSecondOrderTypeInference( ) : (E) → E Please specify it explicitly.
firstOrderFnWithSecondOrderTypeInference<Int>()(1234)
works because there's no type inference for
E
of the second rank function. I guess what I'm looking for is a
why it's like this so I can understand the language a bit better. I know that C++ is the same way, same with Typescript, so I wonder if there's an underlying reason.