scala - Provide type-class when implementing/override method -
i prefer work more type-classes having issues: given following interface
trait processor[a] { def process[b](f: => b): processor[b] }
i have implementation needs ordering[a]
other reasons. hence method process
needs ordering[b]
construct processor[b]
.the following do, not work:
class plant[a, oa <: ordering[a]] extends processor[a] { def process[b:ordering](f: => b): processor[b] = null // plant[b, ob <: ordering[b]] }
how can provide ordering[b]
implementation of process
?
i know reason is, ordering[a]
passed implicit second argument. don't know shouldn't there special support type-classes in scala similar haskell recognize want (only allow b
s have ordering
) in implementation above without "workaround"?
no, , shouldn't work @ all. given defnition of processor
, code compile:
val processor: processor[int] = foo() // foo() function returns processor processor.process[object](x => new object())
now if foo
implemented as
def foo() = new plant[int]()
then process
method won't work b = object
.
Comments
Post a Comment