mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[ocaml/en] Change the example of mutually recursive functions
Change the example to a meaningful and self-contained example of mutually recursive functions.
This commit is contained in:
parent
6edf12c4d7
commit
8c70acc9fb
@ -144,11 +144,16 @@ x + y ;;
|
|||||||
(* Alternatively you can use "let ... and ... in" construct.
|
(* Alternatively you can use "let ... and ... in" construct.
|
||||||
This is especially useful for mutually recursive functions,
|
This is especially useful for mutually recursive functions,
|
||||||
with ordinary "let .. in" the compiler will complain about
|
with ordinary "let .. in" the compiler will complain about
|
||||||
unbound values.
|
unbound values. *)
|
||||||
It's hard to come up with a meaningful but self-contained
|
let rec
|
||||||
example of mutually recursive functions, but that syntax
|
is_even = function
|
||||||
works for non-recursive definitions too. *)
|
| 0 -> true
|
||||||
let a = 3 and b = 4 in a * b ;;
|
| n -> is_odd (n-1)
|
||||||
|
and
|
||||||
|
is_odd = function
|
||||||
|
| 0 -> false
|
||||||
|
| n -> is_even (n-1)
|
||||||
|
;;
|
||||||
|
|
||||||
(* Anonymous functions use the following syntax: *)
|
(* Anonymous functions use the following syntax: *)
|
||||||
let my_lambda = fun x -> x * x ;;
|
let my_lambda = fun x -> x * x ;;
|
||||||
|
Loading…
Reference in New Issue
Block a user