@ -71,32 +71,47 @@ us a line at cla@fb.com. Thanks!
### OCaml
- Follow the ocp-indent style in infer/.ocpindent for indentation.
- The module IStd (infer/src/base/IStd.ml) is automatically opened in every file. Beware that this
can cause weird errors such as:
```
$ pwd
/somewhere/infer/infer/src
$ cat base/toto.ml
let b = List.mem true [true; false]
$ make
[...]
File "base/toto.ml", line 1, characters 17-21:
Error: This variant expression is expected to have type 'a list
The constructor true does not belong to type list
```
- Spaces around binary operators, e.g., `let x = a + 5` .
If your new module cannot compile with `IStd` , for instance because it's generated code, modify
the line in infer/src/Makefile that adds `-open IStd` so that your module is excluded (see how
it's done for other such modules, eg IStd.ml).
- Spaces around parentheses, no space inside parentheses.
- All modules open `IStd` using `open! IStd` . This is to make that fact more explicit (there's also
the compilation flag mentioned above), and also it helps merlin find the right types. In
particular this also opens `Core.Std` .
- Spaces around braces and brackets, spaces inside braces and brackets.
- Do not add anything to `IStd` unless you have a compelling reason to do so, for instance if you
find some utility function is missing and is not provided by
[`Core` ](https://ocaml.janestreet.com/ocaml-core/latest/doc/core/ ).
- Space after `,` and `;` , e.g. `let (a, b) = ({ foo = 4; }, ())` .
- Polymorphic equality is disabled; use type-specific equality instead, even for primitive types
(e.g., `Int.equal` ). However, if your module uses a lot of polymorphic variants with no arguments
you may safely `open! PVariant` .
- Terminate multi-line values such as lists and records with `;` so that it's easy to add new lines
without modifying existing ones. For instance:
```OCaml
let foo = [
value1;
value2;
]
If you try and use polymorphic equality `=` in your code you will get a compilation error, such as:
```
Error: This expression has type int but an expression was expected of type
[ `no_polymorphic_compare ]
```
- All modules open `IStd` , using `open! IStd` . In particular this also opens `Core.Std` . Do not add
anything to `IStd` ; if you find some utility function is missing (and not provided by
[`Core` ](https://ocaml.janestreet.com/ocaml-core/latest/doc/core/ )), add it to `Utils` .
- Alias and use `module L = Logging` for all your logging needs. Refer to its API in Logging.mli for
documentation.
- Polymorphic equality is disabled; use type-specific equality instead, even for primitive types
(e.g., `Int.equal` ). However, if your module uses a lot of polymorphic variants you may
`open! PVariant` .
- Check that your code compiles without warnings with `make -j test_build` (this also runs as part
of `make test` ).
- Apart from `IStd` and `PVariant` , refrain from globally `open` ing modules. Using local open
instead when it improves readability: `let open MyModule in ...` .
@ -129,7 +144,24 @@ module MF = MarkupFormatter
- Use the `_hum` suffix to flag functions that output human-readable strings.
- Check that your code compiles without warnings with `make -j test_build` .
- Follow the ocp-indent style in infer/.ocpindent for indentation.
- Spaces around binary operators, e.g., `let x = a + 5` .
- Spaces around parentheses, no space inside parentheses.
- Spaces around braces and brackets, spaces inside braces and brackets.
- Space after `,` and `;` , e.g. `let (a, b) = ({ foo = 4; }, ())` .
- Terminate multi-line values such as lists and records with `;` so that it's easy to add new lines
without modifying existing ones. For instance:
```OCaml
let foo = [
value1;
value2;
]
```
### Reason