File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ trait TC [F [_]]
2
+
3
+ object TC {
4
+ def check [F [_], A ](x : F [A ])(implicit F : TC [F ]): Unit = ()
5
+ }
6
+
7
+ case class Foo [+ E , + A ](value : A )
8
+
9
+ object Foo {
10
+ type WithList [+ E , + A ] = Foo [List [E ], A ]
11
+
12
+ implicit def instance [E ]: TC [[x] =>> Foo [E , x]] =
13
+ new TC [[x] =>> Foo [E , x]] {}
14
+ }
15
+
16
+ val x1 : Foo [List [String ], Int ] = Foo (1 )
17
+ val x2 : Foo .WithList [String , Int ] = Foo (1 )
18
+
19
+ def test =
20
+ TC .check(x1)
21
+ TC .check(x2)
Original file line number Diff line number Diff line change
1
+ import scala .language .implicitConversions
2
+
3
+ class Ops [A ](a : A ) {
4
+ def bar : Unit = ()
5
+ }
6
+
7
+ implicit def toOps [A ](a : A ): Ops [A ] = new Ops [A ](a)
8
+
9
+ type Id [A ] = A
10
+
11
+ class Foo [A ](val value : Id [A ]) {
12
+ def same : Foo [A ] = new Foo [A ](value)
13
+ def map [B ](f : A => B ): Foo [B ] = new Foo [B ](f(value))
14
+ }
15
+
16
+ val x : Int = 1
17
+ val foo : Foo [Int ] = new Foo (1 )
18
+
19
+ val res1 = x.bar
20
+ val res2 = foo.value.bar
21
+ val res3 = foo.same.value.bar
22
+ val res4 = foo.map[Int ](_ + 1 ).value.bar
23
+ val res5 = foo.map(_ + 1 ).value.bar
You can’t perform that action at this time.
0 commit comments