scala - Implicit parameter resolution given multiple type parameters -


i'm using type class requires types a have instances of scalaz's order[a]. in use case, a java class--in particular joda time's localdate. class has natural ordering implements comparable.

i couldn't find order instance comparables in scalaz itself, tried writing 1 myself:

implicit def comparableorder[a, b]   (implicit ev0: <:<[a, b],             ev1: <:<[a, comparable[b]]): order[a] = new order[a] {   override def order(x: a, y: a): ordering = ordering.fromint(x.compareto(y)) } 

however, after putting definition scope, following lines fail compile:

implicitly[order[localdate]] implicitly[order[localdate <:< comparable[localdate]]] 

however, following does:

implicitly[order[localdate <:< comparable[readablepartial]]] 

as following after hard-code implicit val containing order instance i'm looking for:

implicit val localdateorder = comparableorder[localdate, readablepartial] implicitly[order[localdate]] 

is there way can scala compiler pick instance automatically? implicit val works in case becomes unwieldy nested structures. i'm using scala 2.10.4.

edit: i've tried test on as implement comparable[a] rather comparable[b] b superclass of a. still doesn't seem work:

class myint(n: int) extends comparable[int] {   override def compareto(o: int): int = n - o } implicit def comparableorder[a <: comparable[a]]: order[a] = new order[a] {   override def order(x: a, y: a): ordering = ordering.fromint(x.compareto(y)) } implicitly[order[myint]] 


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -