Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>&lt;:&lt;</code> type is defined in <a href="https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/src/library/scala/Predef.scala" rel="noreferrer">Predef.scala</a> along with the related types <code>=:=</code> and <code>&lt;%&lt;</code> as follows:</p> <pre><code>// used, for example, in the encoding of generalized constraints // we need a new type constructor `&lt;:&lt;` and evidence `conforms`, as // reusing `Function2` and `identity` leads to ambiguities (any2stringadd is inferred) // to constrain any abstract type T that's in scope in a method's argument list (not just the method's own type parameters) // simply add an implicit argument of type `T &lt;:&lt; U`, where U is the required upper bound (for lower-bounds, use: `U &lt;: T`) // in part contributed by Jason Zaugg sealed abstract class &lt;:&lt;[-From, +To] extends (From =&gt; To) implicit def conforms[A]: A &lt;:&lt; A = new (A &lt;:&lt; A) {def apply(x: A) = x} // not in the &lt;:&lt; companion object because it is also intended to subsume identity (which is no longer implicit) </code></pre> <p>This uses the Scala feature that a generic type <code>op[T1, T2]</code> can be written <code>T1 op T2</code>. This can be used, as noted by aioobe, to provide an evidence parameter for methods that only apply to some instances of a generic type (the example given is the <code>toMap</code> method that can only be used on a <code>Traversable</code> of <code>Tuple2</code>). As noted in the comment, this generalizes a normal generic type constraint to allow it to refer to any in-scope abstract type/type parameter. Using this (<code>implicit ev : T1 &lt;:&lt; T2</code>) has the advantage over simply using an evidence parameter like (<code>implicit ev: T1 =&gt; T2</code>) in that the latter can lead to unintended in-scope implicit values being used for the conversion.</p> <p>I'm sure I'd seen some discussion on this on one of the Scala mailing lists, but can't find it at the moment.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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