From 807a958c78c44a83172724766d446eadb24f8cc5 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Sat, 13 Sep 2014 00:46:46 +0700 Subject: Some information about the need for type annotations in OCaml tutorial. --- ocaml.html.markdown | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ocaml.html.markdown') 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 = -- cgit v1.2.3