Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter: private types #11

Open
mimoo opened this issue Jul 28, 2022 · 0 comments
Open

chapter: private types #11

mimoo opened this issue Jul 28, 2022 · 0 comments

Comments

@mimoo
Copy link
Contributor

mimoo commented Jul 28, 2022

  • can't construct the type manually (it's abstract)
  • but you can deconstruct it (it's not fully abstract)
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 *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant