Ocaml.org tutorial revamping, cont'd - Basic Datatypes

Update of the ocaml.org tutorials continues.

We’d like to have your opinion on this new one:

It addresses datatypes basic concepts. It covers the most common predefined datatypes, variants, and records.

Mutability and references are not covered, and polymorphic variants are neither (we’re planning to work on these as stand-alone tutorials).

We love feedback, we need it.

1 Like

Looks pretty good to me. But:

Like virtually every other OCaml tutorial, it ignores one of the most fundamental properties of the language, which is that there is not one but two type disciplines involved. One for modules, one for everything else. The fourth sentence starts “The OCaml type system…”. Which one?

I’m not sure how to address this best in a tutorial targeting beginners, so I don’t have any alternative to propose ATM. But (IMHO) it is a critical point.

A second observation: the section on options begins thusly: “The option type is also a polymorphic type.” But there is no option type. We can have things like int option and string option, but they do not have type option. I prefer to think of option (and list etc.) as families of types, which is a different concept. I don’t know if it is technically accurate, though. In any case, if your tutorial is targeting rank beginners, an obvious question you can expect is something like “ok you said we had an option type, what are its values?” Etc. Again, I’m not sure how best to address this, but for rank beginners it is clearly a point of potential confusion.

HTH

list and option are technically type constructors: they take a type as argument and the result is a type. However, in most conversations this distinction is blurred and they are talked about as types.

5 Likes

Like virtually every other OCaml tutorial, it ignores one of the most fundamental properties of the language, which is that there is not one but two type disciplines involved. One for modules, one for everything else. The fourth sentence starts “The OCaml type system…”. Which one?

You’re so right. I’m in the process of writing something on polymorphic variants and was thinking, “I should have said there are several type disciplines”

The only trouble I have is hierarchy. I don’t want to say nominal typing is the “default” or “first” one. But I don’t want to say that nominal and structural stand as equal either. Not sure what I mean is clear.

A second observation: the section on options begins thusly: “The option type is also a polymorphic type.” But there is no option type. We can have things like int option and string option, but they do not have type option. I prefer to think of option (and list etc.) as families of types, which is a different concept. I don’t know if it is technically accurate, though. In any case, if your tutorial is targeting rank beginners, an obvious question you can expect is something like “ok you said we had an option type, what are its values?” Etc. Again, I’m not sure how best to address this, but for rank beginners it is clearly a point of potential confusion.

Again, I think you are right. Even if it is not explained in full detail, I believe beginners deserve to be told something without misleading simplifications. I have written something saying “'a list is not a type, it is a family” in the polymorphic variant draft, I will migrate it to the basic datatypes tutorial

Answering @lindig here, I believe the family/type constructor story must be explained together with the common abuse of language. These tutorials are mainly targeted at self-learners who don’t get a chance to ask how to pronounce things or have terminology misuse explanations as side remarks of a lecture.

Thanks again, this is great feedback

2 Likes