I want to take this pattern:
def accept[T](a: RList[T]) = true
def accept[T, V](a: RList[T], b: RList[V])(implicit ev: a.S =:= b.S) = true
def accept[T, V, Q](a: RList[T], b: RList[V], c: RList[Q])(implicit ev: a.S =:= b.S, ev2: b.S =:= c.S) = true
but have it accept a KList
, instead of manually overriding for all arities. Basically I want to say, "Take any number of RList
s, that have the same S
member type"
RList
is a trait, that contains a type S
. (For more background on an RList and why I'm doing this, see: Constrain function based on origin (Path Dependent type? Type Generation?))
It looks like what you are doing is just trying to get the compiler to check that the types agree, since your methods ALWAYS return true.
Can you perhaps, instead of making methods which accept an arbitrary number of these, accept a "List of RLists" which is guaranteed to have S all matching?
Here is how such a list might be constructed:
Now, if we try to construct a RListList that doesn't have all the S types agreeing, the compiler will catch us:
This is using dependent method types, which means you need to use scala 2.10 or you need to compile with the -Ydependent-method-types switch in 2.9.x