Created
April 30, 2022 21:28
-
-
Save matthewcrews/353c4ef1505626ca195837c5af31f533 to your computer and use it in GitHub Desktop.
Define a UoM which can only be created from a "constructor"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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