Skip to content

Instantly share code, notes, and snippets.

@dsyme
Created July 18, 2015 09:41
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 dsyme/b80086ce5c5a0dc1a9f7 to your computer and use it in GitHub Desktop.
Save dsyme/b80086ce5c5a0dc1a9f7 to your computer and use it in GitHub Desktop.
type with optional unit of measure annotation and conversion functions
//custom type
type SomeType(v) = member x.V = v
[<AutoOpen>]
module Aux1 =
//custom type that can carry measure
[<MeasureAnnotatedAbbreviation>]
type SomeType<[<Measure>] 'm>(v) =
member x.V = v
[<AutoOpen>]
module Aux2 =
//module with conversion functions for custom type
module SomeType =
let inline WithMeasure (x : SomeType) : SomeType<'m> = SomeType<_>(x.V)
let inline WithoutMeasure (x : SomeType<'m>) : SomeType = SomeType(x.V)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment