mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Some information about the need for type annotations in OCaml tutorial.
This commit is contained in:
parent
166fb997a0
commit
807a958c78
@ -82,7 +82,13 @@ let foo' = foo * 2 ;;
|
|||||||
(* Since OCaml compiler infers types automatically, you normally don't need to
|
(* Since OCaml compiler infers types automatically, you normally don't need to
|
||||||
specify argument types explicitly. However, you can do it if
|
specify argument types explicitly. However, you can do it if
|
||||||
you want or need to. *)
|
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. *)
|
(* You need to mark recursive function definitions as such with "rec" keyword. *)
|
||||||
let rec factorial n =
|
let rec factorial n =
|
||||||
|
Loading…
Reference in New Issue
Block a user