o1-labs / ocamlbyexample

Learn Ocaml by reading code examples
https://o1-labs.github.io/ocamlbyexample/
69 stars 4 forks source link

chapter: private types #11

Open mimoo opened 2 years ago

mimoo commented 2 years ago
module M : sig type t = private { a : int } val create : unit -> t end = struct type t = { a : int } let create () = { a = 5 } end
(* let a = { M.a = 5 }  <-- not gonna work *)
let a = M.create ();;
(* val a : M.t = {M.a = 5} *)
let M.{ a = b } = a
(* val b : int = 5 *)