Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not sure. Void is not a real value, whereas unit is (unlike the article states) just a normal value, which supports all the things you can do with values, like assigning/let-binding etc.

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.



> I'm not sure. Void is not a real value, whereas unit is (unlike the article states) just a normal value, which supports all the things you can do with values, like assigning/let-binding etc.

This is true, but null is effectively at the bottom of the inheritance hierarchy in that it is a valid value for any (pointer) type (in C/C++/Java etc.), while unit cannot be used that way. The relationship between unit and void is that if you were porting a program from an imperative language with void to OCaml, you would generally replace any place where you returned void or took no arguments/void as the argument with unit. Like void it conveys no real information.


> You could note that enums are sort-of-kind-of sum types in C.

I think I'd compare them more to tagged unions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: