the_structure_of_ocaml_programs » discussion

= <> ==

I'm a bit uneasy with the way = and == are used in the example.

Specially to the C-trained eye, it will look like "= is used for declarations and == is used for comparisons", which is incorrect in Ocaml.

# 3.0 == 3.0 ;;
- : bool = false

Oops!

# let rec inf_list = 1 :: inf_list in inf_list = inf_list ;;

Infinite loop, oops again!

The example given will run fine (Ocaml silently converts physical equality to structural equality for non-structured values like ints), but in some more complex cases it will bite to mistake one for another.

And worse, the type system won't help to spot those mistakes. So I think the distinction should be made clear from the beginning.

(I took the "structured value" wording from the ORA book, but I tend to use the boxed/unboxed wording myself)

---

I replaced the "==" by "=". Any objection? Martin

---

There's some changes going on with the description of ;. ; is not a function, it doesn't have a type, certainly not unit -> 'b -> 'b. It's a language construct. The parser is even a bit picky about when ;-expressions are allowed and when they're not. (ex. IF seq_expr THEN expr ELSE expr -> allowed between IF/THEN, but not between THEN/ELSE) The specific rules get complicated, but the comparison with C's comma operator makes great sense. Maybe it's best to just describe as the sequencing operator: for a : unit, a ; b does a (for its side effect) and then returns the result of b. Maybe we can keep the 1 + (print_endline "foo"; 2) example, as the other examples start pretty complicated.