text
stringlengths
0
601k
let open_account (initial_pass: passwd) : bank_account = let cur_pwd = ref initial_pass in let balance = ref 0 in let failure_count = ref 0 in { update_pass = (fun attempted_pwd new_pwd -> if attempted_pwd = !cur_pwd then (failure_count := 0; cur_pwd := new_pwd) else if attempted_pwd <> !cur_pwd then (failure_count := ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes; edges = useful} = g in begin let rec helper useful vertex list = match useful with | [] -> list | [(v1, v2, w)] -> if v1 = vertex then helper [] vertex ((v2, w) :: list) else helper [] vertex list | [(v1, v2, w); rest] -> if v1 = vertex then h...
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_weight: weight) : ('a list * weight) = let (a,weight) = node in if a = b then (List.rev (b :: visited), (total_weight + weight)) else if List.mem a visited then raise Fail else aux_list (ne...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_weight: weight) : ('a list * weight)= let (a,weight) = node in if a = b then (List.rev (b :: visited), (total_weight + weight)) else if List.mem a visited then ([],0) else aux_list (neighb...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths_list big_list big_weight = match paths_list with | (list, weight):: rest -> if weight > big_weight then helper rest list weight else if weight = big_weight then if List.length list > List.length big_list then helper r...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let error_count = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !password then (password := new_pass; error_count := 0) else (error_count := (!error_count + 1); raise wrong_pass)); depos...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc node -> let (start,dest,w) = node in if start = vertex then (dest, w) :: acc else acc ) [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : ('a * weight) list) : ('a list * weight) = let (value,_) = node in if value = b then (List.map (fun ((n, _): ('a * weight)) -> n) visited, List.fold_right (fun (n: ('a * weight)) (w: weight) -> let (_,w1) ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : ('a * weight) list) fc sc : ('a list * weight)= let (value,_) = node in if value = b then sc (List.rev (List.map (fun ((n, _): ('a * weight)) -> n) visited), List.fold_left (fun (w: weight) (n: ('a * weig...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match (find_all_paths g a b) with | [] -> None | paths -> Some (List.fold_left (fun (max: ('a list * weight)) (path: ('a list * weight)) -> let (_, w1), (_, w2) = max, path in if w2 > w1 then path else max ) ([], 0) paths);;
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let balance = ref 0 in let pw_tries = ref 0 in { update_pass = (fun old_pw new_pw -> if !pw <> old_pw then raise wrong_pass else (pw := new_pw; pw_tries := 0) ); deposit = (fun user_pw deposit_val -> if !pw_tries >= 5 then raise too_m...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neighbours_helper edges vertex acc = match edges with | [] -> acc | (v1, v2, weight) :: xs -> if v1 = vertex then neighbours_helper xs vertex ((v2, weight) :: acc) else neighbours_helper xs vertex acc in neighbours_helper g.edges vertex [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (vertex : 'a) (visited: 'a list) total_weight : ('a list * weight) = let neighbours_lst = neighbours g vertex in let not_visited_neighbours = List.filter (fun (el,_) -> not (List.mem el visited)) neighbours_lst in aux_list not_visited_n...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let vertex, _ = node in let neighbours_lst = neighbours g vertex in let not_visited_neighbours = List.filter (fun (el, _) -> not (List.mem el visited)) neighbours_lst ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in let rec helper paths long_path long_weight = match paths with | [] -> long_path, long_weight | (path,weight) :: xs -> if weight > long_weight then helper xs path weight else helper xs long_path long_wei...
let open_account (initial_pass: passwd) : bank_account = let p = ref initial_pass in let b = ref 0 in let w = ref 0 in { update_pass = (fun o n -> if o = !p then (p := n; w := 0;) else (w := !w + 1; raise wrong_pass)); retrieve = (fun d a -> if !w > 4 then raise too_many_failures else if d = !p then (w := 0; if a < 0 t...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = match g.nodes with | [] -> [] | _ -> let f = fun (p: 'a * 'a * weight) (l: ('a * weight) list) -> let (d, a, w) = p in if d = vertex then (a, w) :: l else l in List.fold_right f g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list): ('a list * weight) = let (v, w) = node in let p = v :: visited in if v = b then (List.rev p, w) else let j = fun (x: 'a * weight) (n: 'a) (r: bool) -> let (y, _) = x in r || (y = n) in let f = fu...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v, w) = node in let p = v :: visited in if v = b then sc p w else let j = fun (x: 'a * weight) (n: 'a) (r: bool) -> let (y, _) = x in r || (y = n) in let f = fun ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let x = List.fold_right (fun (p: 'a list * weight) (q: 'a list * weight): ('a list * weight) -> let (_, r) = p in let (_, s) = q in if r > s then p else q) (find_all_paths g a b) ([], 0) in if x = ([], 0) then None else Some x;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let account_balance = ref 0 in let incorrect_guesses = ref 0 in let f1 previous_password_guess new_password = if previous_password_guess = !password then let _ = incorrect_guesses := 0 in password := new_password else let _ = in...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f array element = match element with | (in_edge, out_edge, edge_weight) when in_edge = vertex -> (out_edge, edge_weight) :: array | _ -> array in List.fold_left f [] g.edges let is_visited node array = List.exists ((=) node) array;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_weight : weight) : ('a list * weight) = let (node_value, node_weight) = node in if node_value = b then (node_value :: visited, total_weight + node_weight) else let path = node_value :: visi...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max = ref 0 in let f acc path = let (acc_path, acc_value) = acc in let (path_path, path_value) = path in if path_value >= acc_value then (path_path, path_value) else (acc_path, acc_value) in let paths = find_all_paths g a b in match p...
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let blc = ref 0 in let wrong_cnt = ref 0 in let update_pass (attempt_pass : passwd) (new_pass : passwd) : unit = if (attempt_pass = !pass) then ( wrong_cnt := 0; pass := new_pass; ) else ( wrong_cnt := !wrong_cnt + 1; raise wrong_pa...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if List.mem vertex g.nodes then ( let split (a, b, c) = (a, (b, c)) in List.fold_left (fun acc x -> if fst (split x) = vertex then snd (split x) :: acc else acc) [] g.edges ) else raise Fail ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let adj = neighbours g (fst node) in if (fst node = b) then ([b], snd node) else if List.mem (fst node) visited then raise Fail else ( let x = (aux_list adj ((fst node) :: v...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let adj = neighbours g (fst node) in if (List.mem (fst node) visited) || (adj = []) then (fc ()) else ( aux_list adj ((fst node) :: visited) fc (fun (u, w) -> sc (((fs...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | x :: xs -> let rec find_longest (paths: ('a list * weight) list) (ans: ('a list * weight)) : ('a list * weight) option = match paths with | [] -> Some ans | h :: t -> if (snd h) > (snd ans) t...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let money = ref 0 in let wrong_pass_cnt = ref 0 in { update_pass = (fun old_p new_p -> if old_p <> !password then (wrong_pass_cnt := !wrong_pass_cnt + 1; print_int !wrong_pass_cnt; raise wrong_pass) else (password := new_p; wron...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neigh_h e v acc = match e with | [] -> acc | (a, b, c)::xs -> if a = v then neigh_h xs v ((b, c)::acc) else neigh_h xs v acc in neigh_h g.edges vertex [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc: int) : ('a list * weight) = let v, w = node in if v = b then (v::visited, acc + w) else let neighbs = neighbours g v in let filter_func n = let v, _ = n in not (List.mem v visited) in let fi...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let v, w = node in if v = b then sc ([], 0) else let neighbs = neighbours g v in let filter_func n = let v, _ = n in not (List.mem v visited) in let filtered_neighbs =...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (p: ('a list * weight) list) (l: 'a list * weight) : ('a list * weight) = let _, l_w = l in match p with | [] -> l | (path, w)::xs -> if w > l_w then helper xs (path, w) else helper xs l in let p = find_all_paths g a b in l...
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass and mon = ref 0 and acc = ref 0 in { update_pass = (fun input newpass -> if (input = !pass) then ((pass := newpass );acc:=0) else ((acc:= !acc+1) ; raise wrong_pass) ); deposit = (fun input dep -> if ((input = !pass) && !acc<=4) then (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let c = g.edges in let rec f1 c vertex acc = match c with |(x,y,z)::xl -> if x = vertex then f1 xl vertex ((y,z)::acc) else f1 xl vertex acc |[] -> acc in f1 c vertex [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec tr l k c : 'a list= match l with | [] -> c k | h :: t -> tr t k (fun r -> c (h::r)) in let rec aux_node (node: 'a * weight) (visited : 'a list) w : ('a list * weight) = if (fst node) = b then (visited,w) else aux_list (neighbours g (fst node)) v...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) w sc fc: ('a list * weight) = if (fst node) = b then sc (visited,w) else aux_list (neighbours g (fst node)) visited w sc fc and aux_list (nodes: ('a * weight) list) (visited: 'a list) w sc fc: ('...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let ll = find_all_paths g a b in match ll with |[] -> None |_ -> (fun l ma -> match l with |[] -> None |b::[]-> if (snd b) > (snd ma) then Some b else Some ma |a::b -> if (snd a) > (snd ma) then Some a else Some ma ) ll ([],0);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let failures = ref 0 in let balance = ref 0 in let handle_wrong = fun (failed) -> failures := failed + 1; if !failures > 5 then raise too_many_failures else raise wrong_pass in { update_pass = (fun p -> (fun new_p -> if not (p =...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (acc: ('a * weight) list) (edge: 'a * 'a * weight) = let (here, there, w) = edge in if compare here vertex = 0 then (there, w) :: acc else acc in List.fold_left f [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v, w) = node in if (List.find_opt (fun tmp -> tmp = v) visited) = None then if v = b then (visited @ [v]), 0 else aux_list (neighbours g v) (visited @ [v]) else raise F...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v, w) = node in if (List.find_opt (fun tmp -> tmp = v) visited) = None then if v = b then sc [] 0 else aux_list (neighbours g v) (visited @ [v]) fc sc else fc() a...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in if paths = [] then None else let f = fun (acc_l, acc_w) (l, w) -> if w > acc_w then (l, w) else (acc_l, acc_w) in Some (List.fold_left f ([], 0) paths);;
let check_auth_exceedance (dat : bank_account_data ref) = let (_, _, auth_fails) = !dat in if auth_fails >= 5 then raise too_many_failures ;; let bank_auth f (dat : bank_account_data ref) (passwd : string) = let (amnt, real_passwd, auth_fails) = !dat in check_auth_exceedance dat; if passwd <> real_passwd then (dat := (...
let open_account (initial_pass: passwd) : bank_account = let dat: bank_account_data ref = ref (0, initial_pass, 0) in { update_pass = bank_auth_reset update_pass_base dat; retrieve = bank_auth retrieve_base dat; deposit = bank_auth deposit_base dat; show_balance = bank_auth show_balance_base dat; } ;;
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {edges=edges; nodes=nodes} = g in let op (base: ('a * weight) list) ((v1,v2,w) : ('a * 'a * weight)) = if v1 = vertex then (v2, w) :: base else base in List.fold_left (op) [] edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let {edges=edges; nodes=nodes} = g in let rec aux_node ((ndata, nweight): 'a * weight) (visited : 'a list) : ('a list * weight) = if List.exists (fun nvisited -> nvisited=ndata) visited then raise Fail; let updated_visited = ndata :: visited in if ndata...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let {edges=edges; nodes=nodes} = g in let rec aux_node ((ndata, nweight): 'a * weight) (visited : 'a list) fc : ('a list * weight) = if List.exists (fun nvisited -> nvisited=ndata) visited then (fc ()) else let updated_visited = ndata :: visited in if ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux_find_longest_path (l: ('a list * weight) list) ((c_l, c_weight) : 'a list * weight) : ('a list * weight) = match l with | [] -> (c_l, c_weight) | hd::tl -> let (n_l, n_weight) = hd in if n_weight > c_weight then aux_find_longe...
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let funds = ref 0 in let count = ref 1 in { update_pass = (fun (old_p : passwd) (new_p : passwd) -> match old_p with | old_p when (old_p = !pass) -> pass := new_p ; count := 0 | _ -> count := !count + 1 ; raise wrong_pass ); retriev...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let ls = g.edges in let check_append l n = match n with | (v,b,w) when v = vertex -> (b,w) :: l | _ -> l in List.fold_left check_append [] ls;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (x,w) when x = b -> ([x],w) | (x,w) -> try let _ = List.find ((=)x) visited in raise Fail with Not_found -> try let (l,weight) = aux_list (neighbours g x) ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= match node with | (x,w) when x = b -> (fc [x],sc w) | (x,w) -> try let _ = List.find ((=) x) visited in raise Fail with Not_found -> try aux_list (neighbours g x) (x::...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (pre: ('a list * weight)) (ls : ('a list * weight) list)= let (_,w2) = pre in match ls with | [] -> pre | (l,w)::xs when w > w2 -> helper (l,w) xs | _::xs -> helper pre xs in match find_all_paths g a b with | [] -> None | x...
let open_account (initial_pass: passwd) : bank_account = let incorrect_attempts = ref 0 in let initial_pass = ref initial_pass in let initial_balance = ref 0 in {update_pass = (fun pass1 pass2 -> (if pass1 = !initial_pass then (initial_pass := pass2; incorrect_attempts := 0) else ((incorrect_attempts := (!incorrect_att...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun x -> let (a,b,c) = x in (b,c)) (List.filter (fun x -> let (a,b,c) = x in a = vertex) g.edges);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (w : weight): ('a list * weight) = let (x,y) = node in if x = b then (visited@[x], y+w) else if not(List.mem x visited) then (aux_list (neighbours g x) (visited@[x]) (w+y)) else raise Fail and aux...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc (w : weight): ('a list * weight)= let (x,y) = node in if x = b then sc (visited@[x], y+w) else if not(List.mem x visited) then (aux_list (neighbours g x) (visited@[x]) fc sc (w+y)) else fc(...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths acc = match paths with |[] -> acc |hd::tl -> let (a,b) = hd in helper tl (b::acc) in let rec helper2 paths acc = match paths with |[] -> None |hd::tl -> let (a,b) = hd in if List.for_all (fun x -> x < b+1) acc then So...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let bal = ref 0 in let attempts = ref 0 in { update_pass = (fun old_pw new_pw -> if old_pw = !password then attempts := 0 else attempts := !attempts + 1 ; if old_pw = !password then password := new_pw else raise wrong_pass ); de...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right(fun x y -> let (a,b,c) = x in if a = vertex then y@[b,c] else y) g.edges [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let start = neighbours g a in let rec aux_node (poids : weight) (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if not( List.exists(fun a -> a=(fst(node))) visited) then let visited = (fst(node))::visited in let poids = poids + (snd(node)...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc wc : ('a list * weight)= let (x,y) = node in if not( List.mem x visited) then if (x = b) then (List.rev (x::visited), wc y) else aux_list (neighbours g (fst(node))) (x::visited) fc (fun w -> w...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f = find_all_paths g a b in if f = [] then None else let rec compare (w :weight) (p :'a list) (lst : ('a list * weight) list ) : ('a list * weight) option= match lst with | [] -> Some(p,w) |(x,y)::tl -> if y > w then let p = x in let ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neigh_aux l v = match l with | (a,b,w)::t -> if v = a then (b,w)::neigh_aux t v else neigh_aux t v | [] -> [] in neigh_aux g.edges vertex;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (city, weight) = node in if (city = b) then ([city],weight) else if ( (List.mem city visited) ) then raise Fail else let (path,cost) = (aux_list (neighbours g city) (cit...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fail succeed: ('a list * weight)= let (city, weight) = node in if (city = b) then succeed ([city],weight) else if ( (List.mem city visited) ) then fail () else let succeed2 = ((fun (z,k) -> succe...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l = (find_all_paths g a b) in match l with | [] -> None | g::[] -> Some g | g::gs -> Some ( let rec long l (x,y) = match l with |[] -> (x,y) |(p,w)::[] -> if (w > y) then (p,w) else (x,y) |(p,w)::g -> if (w > y) then long g (p,w) else...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let numOfTrial = ref 0 in { update_pass = (fun (old_passwd:passwd) (new_passwd:passwd) -> if ( old_passwd <> (!password)) then( numOfTrial := !numOfTrial + 1; raise wrong_pass ) else (password := new_passw...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let filter result (e: ('a * 'a * weight))= match e with | (v,n,w) when (v = vertex)-> ((n,w)::result) | _ -> result in List.fold_left filter [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let vertex=(fst node) and vertex_weight=(snd node) in if (List.exists ((=) vertex) visited) then raise Fail else if ( vertex = b) then ( [b],vertex_weight ) else let path=(a...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight)= let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = let vertex=(fst node) and vertex_weight=(snd node) in if (List.exists ((=) vertex) visited) then raise Fail else if ( vertex = b) then ( fc [b], sc vertex_weight ) els...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = (find_all_paths g a b) in match paths with |[] -> None |_ -> let rec helper list = match list with |[] -> raise Fail |x::xs -> if List.for_all (fun r-> (snd r) <= snd x) paths then (Some x) else helper xs in helper paths ;;
let open_account (initial_pass: passwd) : bank_account = let pd= ref initial_pass in let balance = ref 0 in let wrong= ref 0 in { update_pass =( fun a b -> if !pd = a then (let _ = (wrong:=0) in pd:=b) else (let _ = (incr wrong) in raise wrong_pass; ) ) ; deposit= (fun a b -> if !wrong>=5 then raise too_many_failures e...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge list (v1, v2, w ) = if v1 = vertex then (v2,w) :: list else list in List.fold_left edge [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplemented ();;
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let tryCount = ref 0 in let password = ref initial_pass in let update_pass (current_pass : passwd) (new_pass : passwd) : unit = if current_pass = !password then password := new_pass else ( tryCount := !tryCount + 1 ; raise wrong_pass; ) in ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = notimplemented ();;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplemented ();;
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu...
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (...
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ...
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct...
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni...
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu...
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (...
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ...
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct...
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni...
let rec unused_vars = function | Var _ | I _ | B _ -> [] | If (e, e1, e2) -> unused_vars e @ unused_vars e1 @ unused_vars e2 | Primop (_, args) -> List.fold_left (fun acc exp -> acc @ unused_vars exp) [] args | Let (x, e1, e2) -> let unused = unused_vars e1 @ unused_vars e2 in if List.mem x (free_variables e2) then unu...
let rec subst ((e', x) as s) exp = match exp with | Var y -> if x = y then e' else Var y | I n -> I n | B b -> B b | Primop (po, args) -> Primop (po, List.map (subst s) args) | If (e, e1, e2) -> If (subst s e, subst s e1, subst s e2) | Let (y, e1, e2) -> let e1' = subst s e1 in if y = x then Let (y, e1', e2) else let (...
let rec eval exp = match exp with | I _ -> exp | B _ -> exp | Fn _ -> exp | Var x -> raise (Stuck (Free_variable x)) | Primop (po, args) -> let args = List.map eval args in begin match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v end | If (e, e1, e2) -> begin match eval e with | B true -> ...
let rec infer ctx e = match e with | Var x -> begin try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) end | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> begin match infer ctx e with | Bool -> let t1 = infer ct...
let unify : utp -> utp -> utp UTVarMap.t = let rec unify (substitution : utp UTVarMap.t) (t1 : utp) (t2 : utp) : utp UTVarMap.t = match t1, t2 with | UInt, UInt | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> raise NotImplemented | UTVar a, _ -> uni...