Type definitions, like type t = | A | B;, will have to be in both files. Type annotations are only necessary in .rei files. For example:
/* .re file */typet=|A|B;/* type definition */leta=A;/* type is inferred */letb=B;/* type is inferred */lettoString=/* type is inferred */fun|A=>"A"|B=>"B";/* .rei file */typet=|A|B;/* type definition */leta:t;/* type annotation */letb:t;/* type annotation */lettoString:t=>string;/* type annotation */
Whether you want to also annotate the types of the values in your .re file too is a matter of preference. Sometimes they can help you understand and debug code, but the compiler rarely needs them.
Very often, you won't need to copy the whole type definition to the .rei file, and you can keep it opaque instead. This is handy when your data is complicated and you don't want to leak its internal complexities across your whole project.
Regarding the rei files. Is it intended that the .re files also have types? Isn't it duplicate work to have types in both?
Type definitions, like
type t = | A | B;
, will have to be in both files. Type annotations are only necessary in .rei files. For example:Whether you want to also annotate the types of the values in your .re file too is a matter of preference. Sometimes they can help you understand and debug code, but the compiler rarely needs them.
Very often, you won't need to copy the whole type definition to the .rei file, and you can keep it opaque instead. This is handy when your data is complicated and you don't want to leak its internal complexities across your whole project.
thanks John, good to know. This was very helpful