text stringlengths 0 601k |
|---|
let eval_tests = [ (Let ("x", I 1, Primop (Plus, [Var "x"; I 5])), I 6); (factorial, factorial_ev); (Apply (Apply (eve1, [I 3]), [I 4]), I 25); (Apply (ex1, [I 1; I 1]), I 2); (Apply (ex2, []), B true); ] |
let infer_tests = [ (([("x", Int)], Var "x"), Int); (([], e7), Arrow ([Int], Int)); (([], infex1), Arrow ([Int], Int)); (([], ex1), Arrow ([Int; Int], Int)); (([], ex2), Arrow ([], Bool)); (([], Apply (infex1, [I 3])), Int); (([], Apply (ex1, [I 3; I 4])), Int); (([], Apply (ex2, [])), Bool); ] |
let rec infer ctx e = begin 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 = in... |
let rec unused_vars = function | I _ -> [] | B _ -> [] | Var _ -> [] | 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 | Fn (xs, e) -> let free_vars_e = free_variables e in let tuple_to_name tuple : name = match tuple ... |
let rec subst ((e', x) as s) exp : exp = match exp with | I n -> I n | B b -> B b | Var y -> if x = y then e' else Var y | 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 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 ( match eval_op po args with | None -> raise (Stuck Bad_primop_args) | Some v -> v ) | If (e, e1, e2) -> ( match eval e with | B true -> eval e1 | ... |
let rec infer ctx e = match e with | Var x -> ( try lookup x ctx with Not_found -> raise (TypeError (Free_variable x)) ) | I _ -> Int | B _ -> Bool | Primop (po, exps) -> let (domain, range) = primopType po in check ctx exps domain range | If (e, e1, e2) -> ( match infer ctx e with | Bool -> let t1 = infer ctx e1 in le... |
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 -> substitution | UBool, UBool -> substitution | UTVar a, UTVar a' when a = a' -> substitution | UArrow (t1, t1'), UArrow (t2, t2') -> unify (unify substitutio... |
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') -> (unify substitution t1 t2; unify substit... |
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') -> substitution | UTVar a, _ -> unifyVar su... |
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') -> unify (unify substitution t1 t2) t1' t2'... |
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') -> begin match cV t1, cV t2 with | true, tr... |
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') -> let u1' = (unify substitution t1' t2') i... |
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') -> (unify (unify substitution t1 t2) t1' t2... |
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') -> unify (unify substitution t1 t2) t1' t2'... |
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') -> unify (unify substitution t1 t2) t1' t2'... |
let unused_vars_tests = [ ( Rec(("fact"),(Arrow([Int],Int)),( Fn([("n",Int);("k",Int)], If((Primop(Equals,[Var "n"; I 0])),(I 1),(Primop(Times,[Var "n"; Apply(Var "fact", [Primop(Minus,[Var "n";I 1])])])))))), ["k"]); (Rec(("fact"),(Arrow([Int],Int)),( Fn([("n",Int);("k",Int)], If((Primop(Equals,[Var "n"; I 0])),(I 1),... |
let subst_tests : (((exp * name) * exp) * exp) list = [ (((I 1, "x"), Let ("y", I 2, Primop (Plus, [Var "y"; Var "x"]))), Let ("y", I 2, Primop (Plus, [Var "y"; I 1]))); (((I 1, "z"), (Fn ([("p", Int)], Primop (Times, [Var "p"; Var "z"])))), (Fn ([("p", Int)], Primop (Times, [Var "p" ; I 1])))); (((Primop(Plus, [I 5; I... |
let eval_tests = [ (Let ("x", I 1, Primop (Plus, [Var "x"; I 5])), I 6); (Apply (ex10, [I 3; I 4]), I 9); (Apply(Fn([("x",Int)], Primop(Times,[Var"x";I 1])), [I 3]), I 3); ( (Rec ("i", Int, Let ("i", I (-5), Var "i"))), I (-5)); (Rec ("s", Arrow ([Int; Int; Bool], Bool), I 17), I 17); ( (Rec ("v", Int, Let ("c", Primop... |
let infer_tests = [ (([("x", Int)], Var "x"), Int); ] |
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 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') -> if ((t1=t2' || t1=t2') && (not (t1=t2)))... |
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') -> if ((t1=t2' || t1=t2') && (not (t1=t2)))... |
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') -> if ((t1=t2' || t1=t2') && (not (t1=t2)))... |
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') -> begin UTVarMap.merge (fun key alpha beta... |
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 (... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.