let _ = Some 5;; let _ = Some "Hello";; let _ = Some (4 + 5);; let _ = None;; let my_div (x: int) (y: int) : int option = if y <> 0 then Some (x / y) else None ;; let my_div_or_def (x: int) (y: int) (d: int) : int = match my_div x y with Some q -> q | None -> d ;; let zero_or_def (x: int) (y: int) (d: int) : int = match my_div x y with None -> d | _ -> 0 ;; let l1 = [];; let l2 = 5::l1;; let l3 = [1; 2; 3; 4];; let l4 = [[1;2]; [3; 4]; []];; let l5 = [["HI"; "Hello"]; []] let is_empty (l: 'a list) : bool = match l with | [] -> true (* 5::(4::[]) *) | a::b -> false ;; let is_empty (l: 'a list) : bool = if l = [] then true else false (* Don't write it that way *) ;; let l6 = [2; 3]::[];; let head_of_list (l: 'a list) : 'a option = match l with | [] -> None | h::_ -> Some h ;; let second_of_list (l: 'a list) : 'a option = match l with | [] -> None | _::[] -> None | _::h2::_ -> Some h2 ;; let second_of_list (l: 'a list) : 'a option = match l with | _::h2::_ -> Some h2 | _ -> None ;; let rec length (l: 'a list) : int = match l with | [] -> 0 | h::t -> 1 + length t ;; let my_div_match (x: int) (y: int) : int option = match y with | 0 -> None | _ -> Some (x / y) ;; let rec sum (l: int list) : int = match l with | [] -> 0 | h::t -> h + sum t ;; let rec last (l: 'a list) : 'a option = match l with | [] -> None | h::[] -> Some h | h::t -> last t ;; let rec range l h : int list = if l > h then [] else l::(range (l + 1) h) ;; let rec append (l1: 'a list) (l2: 'a list) : 'a list = match l1 with | [] -> l2 | h::t -> h::(append t l2) ;;