How does Typed Racket's type system compare to OCaml's type system?

What are the main design options and differences, and how does this affect the way you think about programs?

+3


source to share


2 answers


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.

+7


source


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.



+3


source







All Articles