Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does <:< work?

Tags:

scala

scala> implicitly[Int <:< AnyVal]
res0: <:<[Int,AnyVal] = <function1>

scala> class Foo
defined class Foo

scala> class Bar extends Foo
defined class Bar

scala> implicitly[Foo <:< Bar]
<console>:8: error: could not find implicit value for parameter e: <:<[Foo,Bar]
       implicitly[Foo <:< Bar]
                 ^

scala> implicitly[Bar <:< Foo]
res2: <:<[Bar,Foo] = <function1>

How does <:< constraint work? Or more precisely, where is the implicit definition that supplies the instances of <:<?

like image 486
unknown9070 Avatar asked Jul 21 '11 14:07

unknown9070


People also ask

Is break time considered working hours?

Hours of work is defined as the period during which employees are expected to carry out the duties assigned by their employer. It does not include any intervals allowed for rest, tea breaks and meals.

How do you know if you're valued at work?

You receive support from teammates It's helpful to take notice of how you feel when at work. If you feel supported by your team and your manager, it's likely because they value you. This is a good indicator of being valued at work since your team consistently shows their support so you can succeed.

Who is eligible for overtime pay in Singapore?

Overtime pay Overtime work is all work in excess of the normal hours of work (excluding breaks). You can claim overtime if you are: A non-workman earning up to $2,600. A workman earning up to $4,500.


1 Answers

You can find it in Predef. Implicit method conforms[A] provides these evidences:

implicit def conforms[A]: A <:< A = new (A <:< A) { def apply(x: A) = x }

You can actually try to implement it yourself in order to make it more clear:

abstract class subclassOf[-From, +To] extends (From => To)
implicit def subclassOfCheck[A]: A subclassOf A = new (A subclassOf A) { def apply(x: A) = x }

implicitly[Int subclassOf AnyVal]

class Foo
class Bar extends Foo

implicitly[Bar subclassOf Foo] 
like image 159
tenshi Avatar answered Oct 23 '22 08:10

tenshi