开发者

Can I compose a function that has an implicit argument?

开发者 https://www.devze.com 2023-04-06 12:05 出处:网络
I\'m playing around with hi开发者_StackOverflowgher kinds, and I\'m trying to use compose.I\'ve got the following code:

I'm playing around with hi开发者_StackOverflowgher kinds, and I'm trying to use compose. I've got the following code:

def p2( a : Int) = a + 2
def p3( a : Int) = a + 3
val p5 = p2 _ compose p3
def pn3[T](n : T)(implicit ev : Numeric[T]) = ev.plus(n, ev.fromInt(3))
val pn5 = p2 _ compose pn3

It all works until the last line:

error: could not find implicit value for parameter ev: Numeric[T]

Which makes sense but how do I tell it, "I want Numeric[Int]!"


Trial and error ;)

val pn5 = p2 _ compose pn3[Int]
0

精彩评论

暂无评论...
验证码 换一张
取 消