Skip to content

Instantly share code, notes, and snippets.

@ShahOdin
Last active September 27, 2021 00:32
Show Gist options
  • Save ShahOdin/428c64b91984c2d55160a98e53fa40a5 to your computer and use it in GitHub Desktop.
Save ShahOdin/428c64b91984c2d55160a98e53fa40a5 to your computer and use it in GitHub Desktop.
sealed trait Nat
sealed trait _0 extends Nat
sealed trait _1 extends _0
sealed trait _2 extends _1
sealed trait _3 extends _2
sealed trait _4 extends _3
sealed trait _5 extends _4
sealed trait _6 extends _5
sealed trait _7 extends _6
sealed trait _8 extends _7
sealed trait _9 extends _8
sealed trait _10 extends _9
trait VersionInfo {
type Major <: Nat
type Minor <: Nat
}
object FooClient extends VersionInfo {
type Major = _2
type Minor = _3
def foo = 42
}
def getFoo[MAJ <: Nat, MIN <: Nat](implicit
maj: FooClient.Major =:= MAJ,
min: FooClient.Minor <:< MIN
) = FooClient.foo
//getFoo[_1,_0]// want version 1.0 => fails to compile due to incompatible Major version
getFoo[_2,_2] // want version 2.2 => compiles
getFoo[_2,_3] // want version 2.3 => compiles
//getFoo[_2,_4] // want version 2.4 => fails to compile as that version is not available yet.
//getFoo[_3,_0]// want version 3.0 => fails to compile due to incompatible Major version
@ShahOdin
Copy link
Author

ShahOdin commented Jun 22, 2018

This is a mechanism for versioning mono-repo services. instead of relying on a versioned client or embeding the version information in a header and then realising the server has rejected/deprecated your request.
we can instead make services provide a series of "manifest" objects which contain the type and version information and the client code can fail compilation if the version information is not right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment