19 Jun 2012 13:19
How to Demand a Class to Have a Certain Ctor
Dear all,
In my attempt below
trait BaseExp {
type App <: {def unapply(e: BaseExp, x: String): App}
def apply(x: String): App = App(this, x)//***
}
type App <: {def unapply(e: BaseExp, x: String): App}
def apply(x: String): App = App(this, x)//***
}
I am trying to demand that when e is a BaseExp and x is a String, e(x) should be something of the to-be-materialised-later type App but with the exact contents App(e, x). What I understand from this is that, whilst App should be left to be defined later, a ctor taking a BaseExp and a String should be demanded of it. That's the reason why I put that "
<: {def unapply(e: BaseExp, x: String): App}
" after "type App" above. The compiler doesn't seem to equate my unapply specification with a constructor however. And, I get the following error for the line with a *** mark:
not found: value App
Whilst this attempt of mine doesn't seem to result, I wonder if there is any way to demand a type to have a ctor of a certain signature?
TIA,
--Hossein
Seyed H. HAERI (Hossein)
Research Assistant
Institute for Software Systems (STS)
Technical University of Hamburg (TUHH)
Hamburg, Germany
ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------
RSS Feed