Skip to content

Instantly share code, notes, and snippets.

@EduardoRFS
Created February 19, 2022 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoRFS/a451c737eda3aa186db981a5ac9e35cb to your computer and use it in GitHub Desktop.
Save EduardoRFS/a451c737eda3aa186db981a5ac9e35cb to your computer and use it in GitHub Desktop.
module Fixed_array (P : sig
val length : int
end) : sig
type 'a t
val length : 'a t -> int
val make : 'a -> 'a t
val get : 'a t -> int -> 'a
val set : 'a t -> int -> 'a -> unit
end = struct
type 'a t = 'a array
let length _ = P.length
let make x = Array.make P.length x
let get = Array.get
let set = Array.set
end
module Array_2 = Fixed_array (struct
let length = 2
end)
module Array_3 = Fixed_array (struct
let length = 3
end)
let f (arr : int Array_3.t) = Array_3.set arr 2 3
let arr = Array_2.make 0
let () = f arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment