How does Typed Racket's type system compare to OCaml's type system?
OCaml system type: Hindley-Milner. The type system includes products and functions, but not arbitrary conjunctions. Hindley-Milner is awesome and has stood the test of time for years.
Typed Racket system type: Text input. The advent of typing provides a way to "have your cake and eat it too ... sometimes". In particular, you can use union types and still type-check in a reasonable order, because the type system knows that certain forms of code guarantee certain properties about values ββthat do so through that code.
For example:
(cond [(number? n) (+ 3 n)]
[else 1234])
In this code, TR knows that in the RHS the first cond
"n" clause must have a type number.
TR is awesome and allows static types in a language like Racket where many modules are written in non-statically typed code. The racquet contract system plays a key role in creating this sound type work.
So, overall: they are both amazing.
But very different.
source to share
The main difference for me is that OCaml's type system will always infer the most general type for you, so you don't need to add type annotations (with some minor exceptions, in the objective part of the language). Also, OCaml has things like string polymorphism, class functors, and modules that don't have a direct match in Typed Racket, afaik.
source to share