From 8c70acc9fb102e5884fb9e05c79e07015c3e4188 Mon Sep 17 00:00:00 2001 From: Chenggang Duan Date: Thu, 12 Feb 2015 16:54:26 +0800 Subject: [ocaml/en] Change the example of mutually recursive functions Change the example to a meaningful and self-contained example of mutually recursive functions. --- ocaml.html.markdown | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ocaml.html.markdown b/ocaml.html.markdown index f9db7080..b30d920b 100644 --- a/ocaml.html.markdown +++ b/ocaml.html.markdown @@ -144,11 +144,16 @@ x + y ;; (* Alternatively you can use "let ... and ... in" construct. This is especially useful for mutually recursive functions, with ordinary "let .. in" the compiler will complain about - unbound values. - It's hard to come up with a meaningful but self-contained - example of mutually recursive functions, but that syntax - works for non-recursive definitions too. *) -let a = 3 and b = 4 in a * b ;; + unbound values. *) +let rec + is_even = function + | 0 -> true + | n -> is_odd (n-1) +and + is_odd = function + | 0 -> false + | n -> is_even (n-1) +;; (* Anonymous functions use the following syntax: *) let my_lambda = fun x -> x * x ;; -- cgit v1.2.3 From ea5c3c1f3efd4da9d47a7e108e0c1b92ee6dfeb6 Mon Sep 17 00:00:00 2001 From: Chenggang Duan Date: Thu, 12 Feb 2015 17:02:16 +0800 Subject: [ocaml/en] Fix typo --- ocaml.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocaml.html.markdown b/ocaml.html.markdown index b30d920b..b0027fea 100644 --- a/ocaml.html.markdown +++ b/ocaml.html.markdown @@ -293,7 +293,7 @@ type int_list_list = int list_of_lists ;; (* Types can also be recursive. Like in this type analogous to built-in list of integers. *) type my_int_list = EmptyList | IntList of int * my_int_list ;; -let l = Cons (1, EmptyList) ;; +let l = IntList (1, EmptyList) ;; (*** Pattern matching ***) -- cgit v1.2.3