I want below code to be type-checked.
val f: Int => String = x => "a"
val g: (=> Int) => String = x => "b"
def t(h: ???): String = h(42)
t(f)
t(g)
What should be put in "???"? I have read this link and tried it.
t[Int => String, (=> Int) => String].common
res4s: reflect.runtime.universe.TypeTag[=> Int with Int => String] = TypeTag[=> Int with Int => String]
So I put "=> Int with Int => String" in the ???, but t(g) does not type-check. I have tried "(=> Int with Int) => String" but t(f) does not type-check.
So the question is,
What is the meaning of "=> Int with Int => String" and why t(g) does not type-check
What is the meaning of "(=> Int with Int) => String" and why t(f) does not type-check
What should be put in ???
Thanks a lot.