ocaml

Differences between OCaml compiler and manual


So I was reading http://www.podval.org/~sds/ocaml-sucks.html, which includes this quote (in the context of problems with ocaml):

there are actually three mildly different syntaxes:

  • the official one is described in the manual
  • a superset thereof is accepted by the compiler ocamlc
  • something similar (but ever so slightly different) is accepted by the preprocessor Camlp4 (e.g., it accepts List.map [1;2;3] ~f:fun x -> x, which is also accepted by the top-level, but not the compiler)

What are examples of ocaml code fragments that are accepted by the ocamlc but do not match the manual?

PS - I'm mainly interested in OCaml 4.00.1, but previous versions are also interesting...


Solution

  • One funny example, in the interest of curiosity only:

                      OCaml version 4.00.0
    
    # type 'a weird_list =
        | ()
        | :: of 'a * 'a weird_list;;
    type 'a weird_list = () | :: of 'a * 'a weird_list
    # 1::2::3::();;
    - : int weird_list = :: (1, :: (2, :: (3, ())))
    

    The differences between Camlp4 and the OCaml compiler are sometimes bugs, but most often explained by the difference in parser technology: if you write an idiomatic LR parser and a LL parser for the same language with mildly annoying syntax subtleties, you should not expect both to match perfectly. I don't think this is a problem in practice (but in practice most people don't use Camlp4).