Invoking invoke


#1

I have successfully used member function 'invoke' with various classes. This one gives a compilation error:

package invoke

import kotlin.test.*

fun <X, Y, Z> compose(f: (Y) -> Z, g: (X) -> Y): (X) -> Z = {x -> f(g(x))}

class Reader<E, A>(val runReader: (E) -> A) {
  fun invoke(e: E): A = runReader(e)
  fun <B> fmap(f: (A) -> B): Reader<E, B> = Reader(compose(f, this.runReader))
}

fun main(args: Array<String>) {
  val quadruple: Reader<Int, Int> = Reader{(n: Int) -> 4 * n}

  assertEquals(16, quadruple.invoke(4))   // OK
  assertEquals(16, quadruple(4))           // OK

  // Compilation error: Expecting function type, but found Reader<Int, Int>
  assertEquals(18, quadruple.fmap{(n: Int) -> n + 2}(4))

  assertEquals(18, quadruple.fmap{(n: Int) -> n + 2}.invoke(4))   // OK
}


Any ideas?

#2

It is a known bug. Please vote for it to receive notifications.


#3

Did that.