loading...

re: Type Annotation in ReasonML VIEW POST

FULL DISCUSSION
 

When I’m developing new code, I usually start by annotating functions as much as I can. Without annotations, it’s possible for the type inference to work against you. Suppose you write a function that you think should return one type, but the compiler infers that it returns a different type. The error would be inside the function (causing it to return the type you don’t want) but the error won’t be reported until later when you use the function somewhere else. The compiler isn’t “wrong,” but it can’t necessarily tell you which part of the code needs to be fixed, just where the error occured. By annotating the functions beforehand, you will be able to catch the error early on.

But once code becomes stable, I usually remove the annotations. They seem redundant when the compiler can display them for you in your IDE.

code of conduct - report abuse