diff options
Diffstat (limited to 'ocaml.html.markdown')
| -rw-r--r-- | ocaml.html.markdown | 6 | 
1 files changed, 6 insertions, 0 deletions
| diff --git a/ocaml.html.markdown b/ocaml.html.markdown index bb9a1a75..b9505f13 100644 --- a/ocaml.html.markdown +++ b/ocaml.html.markdown @@ -150,6 +150,8 @@ x + y ;;     works for non-recursive definitions too. *)  let a = 3 and b = 4 in a * b ;; +(* Anonymous functions use the following syntax: *) +let my_lambda = fun x -> x * x ;;  (*** Operators ***) @@ -207,6 +209,10 @@ let bad_list = [1, 2] ;; (* Becomes [(1, 2)] *)  (* You can access individual list items with the List.nth function. *)  List.nth my_list 1 ;; +(* There are higher-order functions for lists such as map and filter. *) +List.map (fun x -> x * 2) [1; 2; 3] ;; +List.filter (fun x -> if x mod 2 = 0 then true else false) [1; 2; 3; 4] ;; +  (* You can add an item to the beginning of a list with the "::" constructor     often referred to as "cons". *)  1 :: [2; 3] ;; (* Gives [1; 2; 3] *) | 
