Type of a function with Implicit parameters in Scala -


i have higher order function takes in parameter function accepts specific implicit parameter.

to more precise, trying make function takes future creation method depends on implicit context , returns method doesn't depend on context.

to more concrete, let's have this:

def foo(a: int)(implicit ctx: executioncontext): future[float] = future { somelongbar... } 

i have method this:

def providectx[a](func: executioncontext => a): = {      val ctx = setupctx      func(ctx) } 

but if call providectx(foo), compiler complains implicit execution context missing.

the fact dealing executioncontext not important. find how write parameter type accept function implicit argument of specific type. understand implicit part curryed argument, in fact have function so: executioncontext => int => future[float], , pretty sure @ runtime, jvm doesn't know that executioncontext implicit, can't make compiler understand that.

the problem foo method, not function, , eta-expansion (which converts methods functions) not attempted until after implicit application. see section 6.26.2 of language specification details, , this issue additional discussion.

one workaround write this:

providectx((ctx: executioncontext) => (a: int) => foo(a)(ctx)) 

i'm not sure more generic solution possible (at least without kind of reflection, etc.), since can't refer foo (except in method call, of course) without implicit in scope.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -