Created
February 7, 2022 05:06
-
-
Save guizmaii/b01b28f5cefb4d7294bdcd81c9b289a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Instance[T] { | |
def t: T | |
} | |
object Instance { | |
def apply[T](v: T): Instance[T] = new Instance[T] { override def t: T = v } | |
} | |
sealed trait Typed { | |
type T | |
} | |
sealed trait TypedValue extends Typed { | |
def value: T | |
} | |
object Typed { | |
def instance(typed: Typed): Instance[typed.T] = | |
typed match { | |
case t: TypedValue => Instance(t.value) // To make this compile: Instance(t.value.asInstanceOf[typed.T]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment