there is a solution here that uses a path dependent type to restore the type from value:
trait IsOption[F]{ type T def apply(f: F): Option[T] } object IsOption{ def apply[F](implicit isf: IsOption[F]) = isf implicit def mk[A] = new IsOption[Option[A]]{ type T = A def apply(f: Option[A]): Option[A] = f } } def getInner[A](in:A)(implicit inner: IsOption[A]): Option[inner.T] = inner(in)
The answer is strongly inspired by this slide of a brilliant presentation: http://wheaties.imtqy.com/Presentations/Scala-Dep-Types/dependent-types.html#/2/1
You have a function that gets opaque A, but you are restoring the fact that this is an option and the internal type is implicit through IsOption[A] .
I understand that this is not exactly what you asked for, but when you use such types depending on the type. you need to have a specific value from which you are restoring the type.
source share