diff options
author | Daniil Baturin <daniil@baturin.org> | 2014-09-13 00:46:46 +0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2014-09-13 00:46:46 +0700 |
commit | 807a958c78c44a83172724766d446eadb24f8cc5 (patch) | |
tree | d5b5136746c0b20a159b439727286597572b87d3 | |
parent | 166fb997a0793067b7aa09091a1c9f76229ea6de (diff) |
Some information about the need for type annotations in OCaml tutorial.
-rw-r--r-- | ocaml.html.markdown | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ocaml.html.markdown b/ocaml.html.markdown index 5be9510b..bb9a1a75 100644 --- a/ocaml.html.markdown +++ b/ocaml.html.markdown @@ -82,7 +82,13 @@ let foo' = foo * 2 ;; (* Since OCaml compiler infers types automatically, you normally don't need to specify argument types explicitly. However, you can do it if you want or need to. *) -let inc_int (x: int) = x + 1 ;; +let inc_int (x: int) : int = x + 1 ;; + +(* One of the cases when explicit type annotations may be needed is + resolving ambiguity between two record types that have fields with + the same name. The alternative is to encapsulate those types in + modules, but both topics are a bit out of scope of this + tutorial. *) (* You need to mark recursive function definitions as such with "rec" keyword. *) let rec factorial n = |