The code:
val pi = 4.0 * delta * (1.0..n).reduce{t, i ->
val x = (i - 0.5) * delta
t + 1.0 / (1.0 + x * x)
}
used to compile and execute fine. In preparing for my Devoxx UK 2015, having updated to plugin 0.12.540, I find I get:
ERROR: src/pi_sequential_reduce.kt: (15, 24) Overload resolution ambiguity:
public final fun times(other: kotlin.Byte): kotlin.Double defined in kotlin.Double
kotlin.deprecated public final fun times(other: kotlin.Char): kotlin.Double defined in kotlin.Double
public final fun times(other: kotlin.Double): kotlin.Double defined in kotlin.Double
public final fun times(other: kotlin.Float): kotlin.Double defined in kotlin.Double
public final fun times(other: kotlin.Int): kotlin.Double defined in kotlin.Double
public final fun times(other: kotlin.Long): kotlin.Double defined in kotlin.Double
public final fun times(other: kotlin.Short): kotlin.Double defined in kotlin.Double
which is rather problematic. So the questions are:
- has something gone awry with the type inferencing with reduce; and
- any idea how to “fix” this for Friday?