DEV Community

Building Coronate: an open source chess tournament manager

John on April 04, 2020

May 2021 update: I wrote this article when Coronate was using ReasonML and ReasonReact. Those projects have since been replaced with ReScript. ReSc...
Collapse
 
darkle profile image
Coop

This is great. I'm just starting to get into reason and its nice to have a real world projects source code to browse for ides. 👍

Collapse
 
vasco3 profile image
JC

Regarding the rei files. Is it intended that the .re files also have types? Isn't it duplicate work to have types in both?

Collapse
 
johnridesabike profile image
John

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 */
type t = | A | B; /* type definition */
let a = A; /* type is inferred */
let b = B; /* type is inferred */
let toString = /* type is inferred */
  fun
  | A => "A"
  | B => "B";

/* .rei file */
type t = | A | B; /* type definition */
let a: t; /* type annotation */
let b: t; /* type annotation */
let toString: 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.

Collapse
 
vasco3 profile image
JC

thanks John, good to know. This was very helpful

Collapse
 
vasco3 profile image
JC

Awesome post!