Type of a function with Implicit parameters in Scala

后端 未结 1 1166
花落未央
花落未央 2020-12-17 01:34

I would like to have a higher order function that takes in parameter a function that accepts a specific implicit parameter.

To be more precise, I am trying to make a

1条回答
  •  囚心锁ツ
    2020-12-17 01:51

    The problem is that foo is a method, not a function, and eta-expansion (which converts methods to functions) is not attempted until after implicit application. See section 6.26.2 of the language specification for the details, and this issue for additional discussion.

    One workaround would be to write something like this:

    provideCtx((ctx: ExecutionContext) => (a: Int) => foo(a)(ctx))
    

    I'm not sure a more generic solution is possible (at least without some kind of reflection, etc.), since we can't even refer to foo (except in a method call, of course) without an implicit in scope.

    0 讨论(0)
提交回复
热议问题