# Reduce function overload resolution problem

**URL:** <https://discuss.kotlinlang.org/t/reduce-function-overload-resolution-problem/238>\
**Category:** Uncategorized\
**Created:** [June 14, 2015, 9:46am UTC](https://discuss.kotlinlang.org/t/reduce-function-overload-resolution-problem/238 "2015-06-14T09:46:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/russel/32/1442_2.png) [@Russel](https://discuss.kotlinlang.org/u/Russel)\
**Post date:** [June 14, 2015, 9:46am UTC](https://discuss.kotlinlang.org/t/reduce-function-overload-resolution-problem/238/1 "2015-06-14T09:46:11Z")

</div>

The code:

val pi = 4.0 \* delta \* (1.0..n).reduce{t, i -\>

&nbsp;&nbsp;val x = (i - 0.5) \* delta

&nbsp;&nbsp;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:

1. has something gone awry with the type inferencing with reduce; and
2.

---

<div class="post-metadata">

**Author:** ![orangy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/orangy/32/1462_2.png) [@orangy](https://discuss.kotlinlang.org/u/orangy)\
**Post date:** [June 14, 2015, 11:55am UTC](https://discuss.kotlinlang.org/t/reduce-function-overload-resolution-problem/238/2 "2015-06-14T11:55:41Z")

</div>

Looks like a bug. Could you please file an issue about it?

Introducing value from reduce helps:

&nbsp;

```kotlin
val r = (1.0..n).reduce { t, i ->
    val x = (i - 0.5) * delta
    t + 1.0 / (1.0 + x * x)
}
val pi = 4.0 * delta * r
```

---

<div class="post-metadata">

**Author:** ![Russel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/russel/32/1442_2.png) [@Russel](https://discuss.kotlinlang.org/u/Russel)\
**Post date:** [June 14, 2015, 12:20pm UTC](https://discuss.kotlinlang.org/t/reduce-function-overload-resolution-problem/238/3 "2015-06-14T12:20:18Z")

</div>

Ilya,

Thanks for the quick response. I should have tried splitting the expression myself.

I have opened [https://youtrack.jetbrains.com/issue/KT-8067](https://youtrack.jetbrains.com/issue/KT-8067)
