|
|
|
|
|
by edwintorok
3998 days ago
|
|
Small nitpick: 'unit' is more like 'void' than 'null'. Think of a procedure that returns nothing in C: it returns void, similarly in OCaml you return unit. I think the equivalent of 'null' would be None, if you think of pointers as 'a option, except you have to handle it explicitly and can't get NullPointerException like you mention. |
|
While at it, let me add some more comments to the article, since the OP was asking for input:
> In Java and JavaScript, any object can be null and it leads to Null Pointer Exceptions at runtime.
I know what is meant, but that is really strangely written, since the only object that can be null is null itself. In JS to pick your example, {} can never be null.
> There are two different forms: SUM types and PRODUCT types
This comes after introducing tuples which are also product types, they even have multiplication signs in their type signature :-)
> SUM types in OCaml are called Variants.
You could note that enums are sort-of-kind-of sum types in C.
Also, you should probably emphasize that your examples use Core which is not the standard library, because the standard library has completely different signatures, has no Option module, etc. You should probably add the relevant open line, otherwise it is confusing for people that some of the examples don't work and produce complicated error messages.