(* Important: For submission, this file must be named Main.ml * * To build: * * ocamlbuild -use-ocamlfind -pkg compsci631 -pkg ppx_test Main.d.byte * * This produces an executable called ./Main.d.byte, which runs all the * test cases in the file. * * By default, OCaml does not display stack traces when an exception occurs. * To enable stack traces, run: * * OCAMLRUNPARAM=b ./Main.d.byte *) (* These are some handy functions from class. *) let rec map (f : 'a -> 'b) (alist : 'a list) : 'b list = match alist with | [] -> [] | h :: t -> f h :: map f t let rec filter (f : 'a -> bool) (alist : 'a list) : 'a list = match alist with | [] -> [] | h :: t -> if f h then h :: filter f t else filter f t let rec length (alist : 'a list) : int = match alist with | [] -> 0 | _ :: tl -> 1 + length(tl) (* Fill in the functions below. Do not change their types. *) let rec map2 (f : 'a -> 'b -> 'c) (alist1 : 'a list) (alist2 : 'b list) : 'c list = failwith "not implemented" let rec zip (alist1 : 'a list) (alist2 : 'b list) : ('a * 'b) list = failwith "not implemented" let rec flatten (alist : 'a list list) : 'a list = failwith "not implemented" let rec flatten3 (alist : 'a list list list) : 'a list = failwith "not implemented" let rec build_list (len : int) (f : int -> 'a) : 'a list = failwith "not implemented" let rec map_list (f : 'a -> 'b list) (alist : 'a list) : 'b list = failwith "not implemented" let rec partition (f : 'a -> bool) (alist : 'a list) : 'a list * 'a list = failwith "not implemented" let rec merge (less_than : 'a -> 'a -> bool) (alist1 : 'a list) (alist2 : 'a list) : 'a list = failwith "not implemented" let rec sort (less_than : 'a -> 'a -> bool) (alist : 'a list) : 'a list = failwith "not implemented" let%TEST "unsurprisingly, addition works correctly" = 1 + 2 = 3 (* Runs all tests declared with let%TEST. This must be the last line in the file. *) let _ = Testing.run_tests ()