30 May 19:27
How to "overload a function with static parameters"?
From: Sorin Miklós Zsejki <zsejki@...>
Subject: How to "overload a function with static parameters"?
Newsgroups: gmane.comp.lang.fortress.general
Date: 2008-05-30 17:29:57 GMT
Subject: How to "overload a function with static parameters"?
Newsgroups: gmane.comp.lang.fortress.general
Date: 2008-05-30 17:29:57 GMT
Let's say I have:
trait P end
trait R[\T extends P\] end
f[\T extends P\](p: T): R[\T\]
Now I add this:
trait SubP extends P end
trait SubR[\T extends SubP\] extends R[\T\] end
and I want an overloading of f like this:
f[\T extends SubP\](p: T): SubR[\T\]
This is not possible because the static parameters of f must exclude
each other. So my question is how to do this _without giving up the
static parameters_.
I know I could do something like:
trait R1 extends R end
trait R2 extends R excludes R1 end
and declaring f for R1 and R2, but what I want is a general
declaration of f and an overloading for the more specific cases like
SubP. I don't want the general case (the first 3 lines of code) to
make any reference to SubP or SubR.
I think with where clauses I could do something like:
trait OverloadsF extends P end
f[\T extends P\](p: T): SubR[\T\] where {T excludes OverloadsF}
and then SubP would also extend OverloadsF. Is that right?
Another question is why the static parameters must exclude each other?
The types of the parameters of overloaded functions don't, so can't
static parameters work similarly?
RSS Feed