Let's imagine that we're building an invoice-management system and we have an Invoice module that defines an invoice type along with a function that other modules can use to create values of that type. This arrangement is shown in the following code:
/* Invoice.re */
type t = {
name: string,
email: string,
date: Js.Date.t,
total: float
};
let make = (~name, ~email, ~date, ~total) => {
name,
email,
date,
total
};
Let's also suppose that we have another module that is responsible for sending emails to customers, as shown in the following code:
/* Email.re */
let send = invoice: Invoice.t => ...
let invoice =
Invoice.make(
~name="Raphael",
~email="[email protected]",
~date=Js.Date.make(),
~total=15.0,
);
send(invoice);
Since the Invoice.t type is exposed, the invoice can be manipulated by Email...