Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Created September 4, 2015 10:11
Show Gist options
  • Save vasily-kirichenko/0806a650c7d808e4eae1 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/0806a650c7d808e4eae1 to your computer and use it in GitHub Desktop.
[<AutoOpen>]
module UoM =
// Units of measure for other than integral types
let inline (++) (w: ^W when ^W: (static member IsMeasureAbbrev: ^tm * ^t -> unit)) (t: ^t) = (# "" t: ^tm #)
let inline (--) (w: ^W when ^W: (static member IsMeasureAbbrev: ^tm * ^t -> unit)) (tm: ^tm) = (# "" tm: ^t #)
[<MeasureAnnotatedAbbreviation>]
type Guid<[<Measure>] 'm> = Guid
[<MeasureAnnotatedAbbreviation>]
type string<[<Measure>] 'm> = string
[<MeasureAnnotatedAbbreviation>]
type bool<[<Measure>] 'm> = bool
[<MeasureAnnotatedAbbreviation>]
type byte<[<Measure>] 'm> = byte
type UoM = UoM
with
static member IsMeasureAbbrev(_: Guid<'m>, _: Guid) = ()
static member IsMeasureAbbrev(_: string<'m>, _: string) = ()
static member IsMeasureAbbrev(_: bool<'m>, _: bool) = ()
static member IsMeasureAbbrev(_: byte<'m>, _: byte) = ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment