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) ;; let rec rev (l: 'a list) : 'a list = match l with | [] -> [] | h::t -> append (rev t) [h] ;; let rev_tr (l: 'a list) : 'a list = let rec rev_tr_helper l a = match l with | [] -> a | h::t -> rev_tr_helper t (h::a) in rev_tr_helper l [] ;; let range_tr l h : int list = let rec range_helper l h a = if l > h then rev_tr a else range_helper (l + 1) h (l::a) in range_helper l h [] ;; let range_tr2 l h = int list = let rec range_helper l h a = if l > h then a else range_helper l (h - 1) (h::a) in range_helper l h [] ;; let sum_tr (l: int list): int = let rec sum_tr_helper (l: int list) (a : int) : int = match l with | [] -> a | h::t -> sum_tr_helper t (a + h) in sum_tr_helper l 0 ;; (* (* Mon = 0, Tues = 1*) let cs440 = (440, "Muller", [1; 3]);; let print_course c = let (num, prof, days) = c in Printf.printf "CS%d is taught by %s\n" num prof ;; *) type course = { num : int; prof : string; days : int list } ;; let cs440 = { num = 440; prof = "Muller"; days = [1;3]};; let print_course c = Printf.printf "CS%d is taught by %s\n" c.num c.prof ;; let print_course {days = d; num; prof} = Printf.printf "CS%d is taught by %s\n" num prof ;; type course2 = { num : int };; type day = Mon | Tue | Wed | Thur | Fri | Sat | Sun;; type course = { num : int; prof : string; days : day list } ;; let cs440 = { num = 440; prof = "Muller"; days = [Tue; Thur]};; let is_weekend day = match day with | Mon | Tue | Wed | Thur | Fri -> false | Sat | Sun -> true ;;