Showcase where type is extremely useful in your program?


I have been a heavy Flow user before I come to ReasonML. In that time, I treated the type system as a type checker, whether I’m passing the right type of argument.

I have been treating ReasonML’s type system like that too, until today, I solved a problem pretty easily by leveraging the full potential of type system. Here is my use case:

CodeMirror’s coordinates system uses 0-origin for both line and column
OCaml’s coordinates system on the other hands, uses 0-origin for line and 1-origin for column.

In previous version, I only have one type

type loc = {
  line: int,
  col: int,

Then I have to remember converting line correctly when moving between compiler <-> editor coords

Whenever I touch that part of the program, I feel like opening a jar full of worms because I always forget to add or subtract lines.

Today, I decided to try a different approach, I have 2 types:

type compilerLoc = {
  cpl_line: int,
  cpl_col: int,

type editorLoc = {
  edi_line: int,
  edi_col: int,

Then I have 2 functions: compilerToEditorLoc and editorToCompilerLoc . From now on, the type checkers will ensure I converted the location correctly.
It works on first try without a bug (so far).
I feel so powerful with ReasonML right now.

If you have usecase for leveraging to prevent bug like this, please share. I would love to learn more.


I use similar pattern a lot here


wow. that’s awesome. thank you


Great example @alexfedoseev !

@thangngoc89 Have you seen this video yet? This example of using ML typing to make invalid states a compile error blew me away! This changes how I think of a simple react state as well.

at 18min:

Question about Facebook's strategy with Reason & Flow

Thank you. Watching it right now


Richard Feldman and Evan Czaplicki are great teachers of making invalid states impossible. Two insightful videos:

Making Impossible States Impossible.

The Life of a File.