Ah, now I get it.
Alberto Ballano
1

Type erasures of their arguments are equal, but function names are different. Full example which compiles without any problems:

sealed class Option<out A>
object None : Option<Nothing>()
data class Some<out A>(val value: A) : Option<A>()

infix fun <A, B> Option<(A)->B>.map(arg: A): Option<B> = when (this) {
is None -> this
is
Some -> Some(value(arg))
}

@JvmName("applyFunction")
infix fun <A, B> Option<A>.apply(f: Option<(A)->B>) = when (this) {
is None -> this
is
Some -> f.map(value)
}
@JvmName("applyToFunction")
inline infix fun <A, B> Option<(A)->B>.apply(o: Option<A>) = o.apply(this)

fun main(args: Array<String>) {
println(Some(2) apply Some { a: Int -> a + 3 }) // Some(value=5)
println(Some { a: Int -> a + 2 } apply Some(3)) // Some(value=5)
}
Show your support

Clapping shows how much you appreciated Миха Горюнов’s story.