4 As far as indentation rules go, ocp-indent should be used as the final word.
6 However, here are some examples.
11 Try to fit a `let ... in` onto one line:
13 let foo = bar x y z in
16 If the expression is too long, first try
19 some_long_expression_bar x y z in
22 If the second line is still too long, fall back to
25 some_long_expression_bar
33 Don't indent the clauses of a standalone match expression
39 However, if the match expression is the RHS of a let expression, do indent them:
41 let bar = match foo with
47 Alternatively, if `foo` is too long, move the `match` to the next line:
50 match some_long_expression arg1 arg2 with
56 If the expression between `match ... with` is too long to fit into one line,
57 split it out as in separate `let` expression. That is, instead of
59 let foo = match some_long_expression
68 let bar = some_long_expression arg1 arg2 in
69 let foo = match bar with
75 Note that the `in` should be on its own line. I.e. avoid
77 let bar = match foo with
85 Function expressions that span multiple lines should be wrapped in a `begin ... end`:
87 List.iter foo begin fun x ->
91 However, expressions on a single line should use parentheses:
93 List.map foo (fun x -> x + 1)
95 In general, function bodies should be indented. However, we make an exception
96 if `fun` comes right after an operator (typically one of `>>=`, `@@`, or `>>|`):
98 some_monadic_x >>= fun x ->
99 some_monadic_y >>= fun y ->
105 Top-level modules (those created by individual files) should be named using
106 Underscore_separated_words. Modules within files should be CamelCase.
108 Top-level module opens should be reserved only for very commonly used modules,
109 like `Utils`. Aside from those, prefer
111 module LMN = Long_module_name
115 let open Long_module_name in
118 Modules should have the name of their containing directory as a prefix. E.g.
119 modules under typing/ should be named as `Typing_foo`.
124 Generally, there are only two cases where parentheses / `begin ... end` are
125 necessary: for nesting `with` clauses and for inserting multiple
126 semicolon-separated expressions into the `then` clause of an `if`-expression.
141 If the test expression is too long, the following is also acceptable:
143 if long_expression arg1 arg2
152 Variants should be named using `Capitalized_underscore_separated_words`.
154 This includes polymorphic variants; i.e. we want `\`Foo` and not `\`foo`. In
155 fact, the OCaml manual suggests that lowercase polymorphic variants may be
156 deprecated in future versions.
161 Boolean function parameters should always be labeled. Consider labeling
162 integer parameters as well.
164 Try to use exhaustive matching whenever possible. That is, avoid the wildcard