Skip to content

Instantly share code, notes, and snippets.

@matthewcrews
Created April 30, 2022 21:28
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 matthewcrews/353c4ef1505626ca195837c5af31f533 to your computer and use it in GitHub Desktop.
Save matthewcrews/353c4ef1505626ca195837c5af31f533 to your computer and use it in GitHub Desktop.
Define a UoM which can only be created from a "constructor"
module Units =
[<Measure>] type private Chicken
module Chicken =
let create x =
if x < 0 then
invalidArg (nameof x) "Cannot have a Chicken <0"
LanguagePrimitives.Int32WithMeasure<Chicken> x
open Units
let myChicken = Chicken.create 1
// The "normal" way to add UoM annotation to a primitive
let failChicken = LanguagePrimitives.Int32WithMeasure<Chicken> 1
let otherFailChicken = 1 * 1<Chicken>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment