Skip to content

Instantly share code, notes, and snippets.

@jliszka
Created June 11, 2012 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jliszka/2910155 to your computer and use it in GitHub Desktop.
Save jliszka/2910155 to your computer and use it in GitHub Desktop.
class !<:<[A, B]
implicit def any[A, B]: A !<:< B = new !<:<[A, B]
implicit def sub1[A, B >: A]: A !<:< B = new !<:<[A, B]
implicit def sub2[A, B >: A]: A !<:< B = new !<:<[A, B]
sealed trait ShardKeyNotSpecified
sealed trait ShardAware
trait Sharded
class ShardingOk[M, S](a: String) { override def toString = a }
implicit def sharded[M <: Sharded, State <: ShardAware]: ShardingOk[M, State] = new ShardingOk("a")
implicit def unsharded[M, State](implicit ev: M !<:< Sharded): ShardingOk[M, State] = new ShardingOk("b")
class A extends Sharded
class B
implicitly[ShardingOk[A, ShardKeyNotSpecified]] // Should fail
implicitly[ShardingOk[A, ShardAware]] // Should succeed
implicitly[ShardingOk[B, ShardKeyNotSpecified]] // Should succeed
/*
Sharded => ShardAware
~Sharded v ShardAware
~(Sharded & ~ShardAware)
~ShardAware => ~Sharded
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment