4 ms·
Why did you stop reading? The TS version has zero type safety (compiler infers any), whereas the RML version will only accept numeric type arguments.
by virtualwhys 7y ago
Why did you stop reading?
The TS version has zero type safety (compiler infers any), whereas the RML version will only accept numeric type arguments.
- kadfak 7y agoIn Reason let sum = (a, b) => a + b; actually accepts only arguments of type int, not any numeric type. The + operator is defined as let (+): (int, int) => int; To have the function accept floats, for example, you would have to use the +. operator like this let sum = (a, b) => a +. b;
- mcv 7y agoI noticed the article had a tendency to compare numbers in Typescript with integers in ReasonML, and I was wondering why. I guess a clearer distinction between the two can be nice, but then how does that compile to javascript?
- yawaramin 7y agoReasonML ints and floats both compile to JavaScript numbers. See https://bucklescript.github.io/docs/en/common-data-types#shared https://bucklescript.github.io/docs/en/common-data-types#sha... for a type mapping table.