example PrivateTypes.re
From this issue.
More of a question than an issue, but wasn't sure where else to ask.
Don't private types achieve the semantics you want? An exposed type which cannot be constructed but can be deconstructed. Are you already aware of this and there's some additional value to the view pattern that I don't understand?
module UserWithView: {
type t;
type view = {
name: string,
age: int,
};
let make: (~name: string, ~age: int) => t;
let view: t => view;
} = {
type t = {
name: string,
age: int,
};
type view = {
name: string,
age: int,
};
let make = (~name, ~age): t => {name, age};
let view: t => view = t => {name: t.name, age: t.age};
};
module PrivateUser: {
type t =
pri {
name: string,
age: int,
};
let make: (~name: string, ~age: int) => t;
} = {
type t = {
name: string,
age: int,
};
let make = (~name, ~age): t => {name, age};
};
let _ = PrivateUser.make(~name="me", ~age=30);
let _ = {PrivateUser.name: "me", age: 30};