Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shishkin
Created August 30, 2014 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shishkin/f4b4cb9d8a9d3959fccc to your computer and use it in GitHub Desktop.
Save shishkin/f4b4cb9d8a9d3959fccc to your computer and use it in GitHub Desktop.
Making incorrect version specifications impossible with F# typesystem
type VersionNumber =
| Major of major: int
| Minor of major: int * minor: int
| Patch of major: int * minor: int * patch: int
type Version =
| Release of VersionNumber
| PreRelease of VersionNumber * string
static member create (x) = Release (Major x)
static member create (x,y) = Release (Minor (x,y))
static member create (x,y,z) = Release (Patch (x,y,z))
static member create (x,pre) = PreRelease (Major x, pre)
static member create (x,y,pre) = PreRelease (Minor (x,y), pre)
type VersionSpec =
| Latest
| AtLeast of Version
| Exactly of Version
| Between of min: Version * max: Version
type PackageSpec = PackageSpec of id: string * version: VersionSpec
type Nuget =
Nuget of string with
static member (>==) (Nuget(id), x) = PackageSpec (id, AtLeast (Release (Major x)))
static member (>==) (Nuget(id), (x,y)) = PackageSpec (id, AtLeast (Release (Minor (x, y))))
static member (>==) (Nuget(id), (x,pre)) = PackageSpec (id, AtLeast (PreRelease (Major x, pre)))
static member (===) (Nuget(id), x) = PackageSpec (id, Exactly (Release (Major x)))
static member (>~~) (Nuget(id), x) =
PackageSpec (id, Between (Release (Major x), Release (Major (x + 1))))
let nuget = Nuget
let x1 = nuget "foo" >== 3
let x2 = nuget "foo" >== (3,2)
let x3 = nuget "foo" >== (3,"beta")
let x5 = nuget "foo" === 3
let x6 = nuget "foo" >~~ 3
@forki
Copy link

forki commented Aug 30, 2014

I like the idea, but can it represent all possible nuget versions?

@forki
Copy link

forki commented Aug 31, 2014

@agross could you list some versions which don't follow this scheme?

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