Skip to content

Instantly share code, notes, and snippets.

@matthewcrews
Last active February 3, 2022 17:29
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/b7928c8d7232df2b16adc42c99cca27b to your computer and use it in GitHub Desktop.
Save matthewcrews/b7928c8d7232df2b16adc42c99cca27b to your computer and use it in GitHub Desktop.
[<Measure>] type Chicken
[<Measure>] type Cow
type Arr<[<Measure>] 'Measure>(v: array<_>) =
let values = v
member _.Item
with inline get (i: int<'Measure>) =
v.[int i]
member _.GetSlice (start, finish) =
let start = defaultArg start 0<_> |> int
let finish = defaultArg finish (1<_> * (v.Length - 1)) |> int
values[start .. finish]
|> Arr<'Measure>
let chickenSizeArray =
[|1.0 .. 10.0|]
|> Arr<Chicken>
let chickenSlice = chickenSizeArray[0<Chicken> .. 2<Chicken>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment