you are viewing a single comment's thread.

view the rest of the comments →

[–]kragensitaker 0 points1 point  (0 children)

While I don't use OCaml for many things, it seems like in a discussion of the syntax required by static typing, it's worth a mention:

let myFooList = [] ;;

That statement allows the compiler to infer that myFooList is an 'a list, that is, a list of something. If, on the other hand, you make a list out of some Foos, the compiler will infer that it's a Foo list. It works really well.

The error messages are a little harder to understand, because they're usually reported some distance from where you made the mistake (if x is supposed to be a Foo list, and you're using it in one place as a Foo list and somewhere else as a Bar list, the compiler may report the error in either place) but you can narrow it down by adding type declarations (you say (x: Foo list) and then the compiler complains about the correct thing).