I have the following module:
type userBuilderType = {
mutable name: string,
};
module BuilderPattern = {
let builder () => {
name: "",
};
let setName = fun name => builder.name = name;
let getName = builder.name;
};
BuilderPattern.setName("Charles");
Js.log(BuilderPattern.getName);
It accomplishes the following:
- Creates type for setter
- builderName object for setting + getting In addition I would like to:
- Be able to retrieve name using a JS.log on getName function
However, in this instance I get back the following error:
This is: unit => userBuilderType But somewhere wanted: userBuilderType
Any suggestions as to how I properly set up the setter/getter is more than appreciated. Thank you.
builderNameis a function fromunittouserBuilderType. You can't access its field directly. If you writelet builderName => { ...instead, it ought to work. - gallais