# part3 - else if n = 0 then x else n_times f (n-1) (f x) let...

This preview shows page 1. Sign up to view the full content.

exception Bad_matrix of string let transpose (x : 'a list list) : 'a list list = match x with | [] -> raise (Bad_matrix "no rows") | [] :: t -> if List.for_all (fun y -> y = []) t then raise (Bad_matrix "no columns") else raise (Bad_matrix "not rectangular") | a :: t -> let m = List.length a in if List.for_all (fun y -> List.length y = m) t then List.fold_right (List.map2 (fun z w -> z::w)) x (List.map (fun x -> []) a) else raise (Bad_matrix "not rectangular") let rec n_times f n x = if n < 0 then failwith "n < 0"
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else if n = 0 then x else n_times f (n-1) (f x) let count_caps lst = List.length (List.filter (fun s -&gt; 0 &lt; String.length s &amp;&amp; 'A' &lt;= String.get s 0 &amp;&amp; String.get s 0 &lt;= 'Z') lst) let dot x y = let compose f g x = f (g x) in let uncurry f (x, y) = f x y in let distribute f (x, y) = ((f x), (f y)) in let zip_pairs (a, b) (x, y) = ((a, x), (b, y)) in let pairwise_mult x y = (distribute (uncurry ( *. )) (zip_pairs x y)) in (compose (uncurry (+.)) (uncurry pairwise_mult)) (x,y)...
View Full Document

Ask a homework question - tutors are online