Skip to content

Instantly share code, notes, and snippets.

@sir-wabbit
Last active March 15, 2017 04:14
Show Gist options
  • Select an option

  • Save sir-wabbit/6a68ae9c3aff10e40f1d14fe8e0f998f to your computer and use it in GitHub Desktop.

Select an option

Save sir-wabbit/6a68ae9c3aff10e40f1d14fe8e0f998f to your computer and use it in GitHub Desktop.
sealed trait Data { self =>
type Type >: self.type <: Data
type Value
implicitly[Type <:< Type#Type]
implicitly[self.type <:< Type]
}
sealed trait DataF[T <: DataF[T]] extends Data { self : T =>
// type Type >: self.type <: DataF[T]
type Type = T
implicitly[T <:< T#Type]
implicitly[Type <:< Type#Type]
implicitly[self.type <:< Type]
implicitly[self.type <:< T]
}
type Same[A <: Data] = A#Type { type Type = A#Type }
////////////////////////////////////////////////////////////////////////////
sealed trait Nat extends DataF[Nat] { type Value = BigInt }
final class Z private () extends Nat { override type Type = Nat }
final class S[N <: Nat] private () extends Nat { override type Type = Nat }
implicitly[Nat <:< Nat#Type]
def f[A <: Nat]: Unit = {
implicitly[A <:< A#Type]
}
f[Nat]
f[Z]
f[S[Z]]
def g[A <: Data]: Unit = {
implicitly[A <:< A#Type]
}
g[Nat]
g[Z]
g[S[Z]]
def h[A <: Data, B <: Same[A]]: Unit = {
implicitly[A <:< A#Type]
implicitly[B <:< B#Type]
implicitly[B <:< A#Type]
implicitly[A <:< B#Type]
implicitly[A#Type <:< B#Type]
implicitly[B#Type <:< A#Type]
implicitly[A#Type =:= B#Type]
}
h[Nat, Nat]
h[Nat, Z]
h[Z, Nat]
h[Z, Z]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment