The TS version has zero type safety (compiler infers any), whereas the RML version will only accept numeric type arguments.
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;I guess a clearer distinction between the two can be nice, but then how does that compile to javascript?
The typescript version will be "inferred" as any, and it will refuse to compile if you set `noImplicitAny`.
> So I stopped reading there.
Because you could not handle the truth?
They're separate concepts. Maybe I want to ensure that I'm receiving a product as it makes no sense to invoke formatName(...) on other things with names like a Cat or Person.
And the generic "thing with a name" one is possible in TypeScript too:
const formatName = (product: {name: string}) => "Name: " + product.nameYes.
> does it infer at use time that the formatName(...) invocation is valid because the argument has a "name" property?
No. OCaml does have a structural object system (https://v1.realworldocaml.org/v1/en/html/objects.html) and it is available to reason, but it's syntactically funky (https://reasonml.github.io/docs/en/object) and as far as I can tell TFA does not use it.
> They're separate concepts.
Yes. Which is why OCaml (and thus Reason) separates it[0] from the nominative "structures".
> Maybe I want to ensure that I'm receiving a product as it makes no sense to invoke formatName(...) on other things with names like a Cat or Person.
You're really deep into this strawmanning thing.
[0] pretty completely, you can't use nominative types in a structural context, they are not compatible. In fact structural types are sets of methods, something which doesn't exist on the nominative side.
In this case it truly is a Product and if you want to reuse a field name you'll need to enclose that type in a module.
Row polymorphic -- "thing with a name" -- is possible through the object system which is accessed through a different syntax, and works like go interfaces in practice.
And this happens all the time.
> Although I didn’t write any types by hand, the arguments of this function are typed. Why don’t we have to write types in ReasonML?
Is perfectly fine for typescript too. As for: So I stopped reading there.