Created
October 5, 2019 14:17
-
-
Save makenowjust/aaadf49760ff3964fdbce4abe43723e9 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
import scala.reflect.runtime.universe.reify | |
object scope { | |
class Int | |
sealed trait List[A] | |
class Nil[A] extends List[A] | |
class Cons[A] extends List[A] | |
class Tree[A] | |
trait HList | |
class HNil extends HList | |
class :*:[H, T <: HList] extends HList | |
trait Coproduct | |
class CNil extends Coproduct | |
class :+:[H, T <: Coproduct] extends Coproduct | |
trait Generic[A] { | |
type R | |
} | |
object Generic { | |
type Aux[A, R0] = Generic[A] { type R = R0 } | |
implicit def list[A]: Aux[List[A], Nil[A] :+: Cons[A] :+: CNil] = ??? | |
implicit def nil[A]: Aux[Nil[A], HNil] = ??? | |
implicit def cons[A]: Aux[Cons[A], A :*: List[A] :*: HNil] = ??? | |
implicit def tree[A]: Aux[Tree[A], A :*: List[Tree[A]] :*: HNil] = ??? | |
} | |
trait Eq[A] | |
object Eq { | |
implicit def int: Eq[Int] = ??? | |
} | |
object DeriveEq { | |
implicit def derive[A, R](implicit AR: Generic.Aux[A, R], R: GEq[R]): Eq[A] = ??? | |
} | |
trait GEq[A] | |
object GEq { | |
implicit def hnil: GEq[HNil] = ??? | |
implicit def hcons[H: GEq, T <: HList: GEq]: GEq[H :*: T] = ??? | |
implicit def cnil: GEq[CNil] = ??? | |
implicit def ccons[H: GEq, T <: Coproduct: GEq]: GEq[H :+: T] = ??? | |
implicit def value[A](implicit A: => Eq[A]): GEq[A] = ??? | |
} | |
object ListInstances { | |
import DeriveEq._ | |
implicit def listEqInstance[A: Eq]: Eq[List[A]] = derive | |
} | |
object TreeInstances { | |
import DeriveEq._, ListInstances._ | |
implicit def treeEqInstance[A: Eq]: Eq[Tree[A]] = derive | |
} | |
} | |
import scope._, TreeInstances._ | |
println(reify(implicitly[Eq[Tree[Int]]]).tree) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment