Can I express `T =:= obj.MyType forSome { val obj :MyClass }`, either as type bounds or through givens in Scala 3?

20 Views Asked by At

Lets say I have a unary evidence type constructor

  class MyEvidence[T]
  object MyEvidence {
    //statically provable implicit/given values for various type arguments.
  }

Now let us have urelated classes

  trait MyClass { type MyType; val myVal :Box[MyType] }
  class Box[T]

Lets us also assume that I not only know for a fact that a given MyEvidence[obj.MyType] exists or any obj :MyClass, but I can also construct it statically, without referencing obj, as a parameterless given value.

Problem:

  1. In code, somewhere I have an obj :MyClass (such that I have no bounds on obj.MyType).
  2. Lets assume I have an implicit conversion Box[T] => Gizmo[T] if an implicit MyEvidence[T] exists (the use case for that evidence).

How can I provide the needed MyEvidence[obj.T], so that the conversion from point 2 exists?

I didn't minimize the question by replacing myVal :Box[MyType] with myVal :MyType (and the conversion to T => Gizmo[T] in case type inference works differently for type parameters and types of values (a hunch that the problem, as defined, may be easier).

0

There are 0 best solutions below