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 bs 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

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -