text
stringlengths
0
601k
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 | B f...
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 let t...
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') -> let substitution = unify substitution t1...
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) th...
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(UnifError (UnifMismatch (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') -> raise(UnifError (UnifMismatch (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') -> raise(UnifError (UnifMismatch (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) th...
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(UnifError (UnifMismatch (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') -> 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') -> let p = unify substitution t1 t2 in let ...
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) -> if x = y then Let (y, subst s e1, e2) else ( let (y, e2) = if Lis...
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 substitution = unify substitution ...
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) -> if x = y then Let (y, subst s e1, e2) else ( let (y, e2) = if Lis...
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 substitution = unify substitution ...
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 substitution' = unify substitution t...
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 substitution' = unify substitution t...
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 y...
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 | B...
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 let t...
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 substitution = unify substitution ...
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 substitution = unify substitution t1...
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') -> UTVarMap.union (fun key d1 d2 -> if d1=d...
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') -> if t1 = t2 && t1' = t2' then 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 unused_vars_tests = [ (Let ("x", I 1, I 5), ["x"]); (Fn ([("x", Int ); ("y", Int);("b", Int ); ("c", Int)], (Primop (Plus, [I 1; I 2] ))), ["x"; "y"; "b"; "c"]); (Apply(e1, [I 3; I 4]), ["b"; "c"]); ((Rec("f", Int, Primop (Plus, [(Fn ([("x", Int )], (Primop (Minus, [Var "x"; I 1])))); (Apply (Var "f", [ (Primop (Mi...
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, "x"),Rec("facti", Int, Var "x")), (Rec("facti", Int, I 1))); ((( Var "f", "fact"), (Rec ("fact", Int, Primop (Plus, [ (Fn ([("x", Int)] , Prim...