Note that there are some explanatory texts on larger screens.

plurals
  1. POCan this be simplified?
    primarykey
    data
    text
    <p>Referring to a <a href="https://stackoverflow.com/questions/5026055/mixing-in-generic-traits-in-parameterized-classes-without-duplicating-type-parame/5028335#5028335">previous answer of mine on stackoverflow</a></p> <p>The core of the complexity is illustrated in just one method:</p> <pre><code>implicit def traversableToFilterOps[CC[X] &lt;: Traversable[X], T] (xs: CC[T])(implicit witness: CC[T] &lt;:&lt; TraversableLike[T,CC[T]]) = new MoreFilterOperations[CC[T], T](xs) </code></pre> <p>With two questions:</p> <ol> <li><p>Is there any way to give the compiler a hint that <code>Map</code> meets the signature <code>CC[X] &lt;: Traversable[X]</code>? I would expect it to match as a <code>Traversable[Tuple2[_,_]]</code> but this doesn't happen. In the end, I had to write a second method taking <code>CC[KX,VX] &lt;: Map[KX,VX]</code>, but that feels redundant</p></li> <li><p><code>witness: CC[T] &lt;:&lt; TraversableLike[T,CC[T]]</code> also seems redundant given the first type parameter, my gut feeling is that this is enforced by the type of <code>Traversable</code> and must <em>always</em> hold true for any possible subclass or value of <code>X</code>, so there should be no reason to explicitly require it as a witness.</p></li> </ol> <p>If I test this using an existential type in the REPL, then the compiler seems to agree with me:</p> <pre><code>scala&gt; implicitly[Traversable[X] &lt;:&lt; TraversableLike[X,Traversable[X]] forSome { type X }] res8: &lt;:&lt;[Traversable[X],scala.collection.TraversableLike[X,Traversable[X]]] forSome { type X } = &lt;function1&gt; </code></pre> <p>Is there therefore any way to do away with the boilerplate?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload