Created
February 3, 2022 16:08
-
-
Save matthewcrews/bea24372de6af4f040ec68a0640289ef to your computer and use it in GitHub Desktop.
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
[<Measure>] type Chicken | |
[<Measure>] type Cow | |
type Arr<[<Measure>] 'Measure>(v: array<'T>) = | |
member _.Item | |
with get (i: int<'Measure>) = | |
v.[int i] | |
let chickenSizeArray = | |
[|1.0 .. 10.0|] | |
|> Arr<Chicken> | |
let cowSizeArray = | |
[|1.0 .. 10.0|] | |
|> Arr<Cow> | |
let chickenIndex = 1<Chicken> | |
// This works | |
let chickenSize = chickenSizeArray[chickenIndex] | |
// This won't compile | |
let cowSize = cowSizeArray[chickenIndex] |
Yeah, I've updated my code since then. Good catch!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a warning on line 13:
FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'T has been constrained to be type 'float'.
Like this it works: