diff options
author | Elena Bolshakova <lena-san@yandex-team.ru> | 2015-06-10 11:34:14 +0300 |
---|---|---|
committer | Elena Bolshakova <lena-san@yandex-team.ru> | 2015-06-10 11:34:14 +0300 |
commit | 193f66553fc114e83e7c4cfb4607e4a1b57c4f09 (patch) | |
tree | 30988e25d31ed6dff83cf409ad093c3c7ec9322c /ocaml.html.markdown | |
parent | 676568cca8731d0dbb2d2bdeff08cc092d283177 (diff) | |
parent | 5086480a04d27cff2380f04609210082000538d4 (diff) |
Merge branch 'master' of https://github.com/adambard/learnxinyminutes-docs
Diffstat (limited to 'ocaml.html.markdown')
-rw-r--r-- | ocaml.html.markdown | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/ocaml.html.markdown b/ocaml.html.markdown index f9db7080..b0027fea 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 ;; @@ -288,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 ***) |