text stringlengths 0 601k |
|---|
type ' s select = ' s ActionOut . select |
type ' s branch = ' s ActionInp . branch |
type ( ' v , ' s ) out = ( ' v , ' s ) ActionOut . out |
type ( ' v , ' s ) inp = ( ' v , ' s ) ActionInp . inp |
let close ( ) = ( ) |
type chan_table = ( string * string , DynChan . chan ) Hashtbl . t |
module UnicastEnv : EnvSpec with type entry = chan_table = struct type entry = chan_table type env_entry += E of entry let name = " unicast " let make_default ( ) = Hashtbl . create 42 let update _param _tbl = ( ) end |
module Lookup = RegisterEnvSpec ( UnicastEnv ) |
let lookup ( t : chan_table ) ( key : string * string ) = match Hashtbl . find_opt t key with | Some ch -> ch | None -> let ch = DynChan . make ( ) in Hashtbl . add t key ch ; ch |
let ( --> ) ra rb lab g env = let g = g env in let ch = lookup ( Lookup . lookup env ) ( ra . role_label . method_name , rb . role_label . method_name ) in let key = DynChan . new_name ch in let b = seq_get rb . role_index g in let g = seq_put rb . role_index g ( ActionInp . make_branch ra . role_label lab . var key b ... |
let ( ==> ) ra rb g env = let g = g env in let ch = lookup ( Lookup . lookup env ) ( ra . role_label . method_name , rb . role_label . method_name ) in let key = DynChan . new_name ch in let b = seq_get rb . role_index g in let g = seq_put rb . role_index g ( ActionInp . make_inp ra . role_label key b ) in let a = seq_... |
let secondary_mask = 0xff lsl 7 let tertiary_mask = 0x7f let primary ce = ( ce land primary_mask ) primary_mask lsr 15 let secondary ce = ( ce land secondary_mask ) secondary_mask lsr 7 let tertiary ce = ce land tertiary_mask let compose_ce w1 w2 w3 = ( w1 lsl 15 ) 15 lor ( w2 lsl 7 ) 7 lor w3 let complete_ignorable = ... |
module Logs = ( val Logs . ( src_log @@ Src . create __MODULE__ ) ) |
module Stack : sig type elt = | Var of Variable . t * Type . t | Expr of Type . t * Type . t type t val empty : t val pop : t -> ( elt * t ) option val push_quasi_solved : t -> Variable . t -> Type . t -> t val push_array2 : Type . t array -> Type . t array -> t -> t val [ @ warning " - 32 " ] pp : t Fmt . t [ @@ ocaml... |
type return = | Done | FailUnif of Type . t * Type . t | FailedOccurCheck of Env . t |
let ( let ) * x1 f = match x1 with Done -> f ( ) | _ -> x1 |
let occur_check env : return = debug ( fun m -> m " [ @< v > Occur check in , @% a ] " @ Env . pp env ) ; let nb_predecessors = Variable . HMap . create 17 in let successors = Variable . HMap . create 17 in let fill_nb_predecessors x ty = let aux y = Variable . HMap . incr nb_predecessors y ; Variable . HMap . add_list... |
let rec process_stack env ( stack : Stack . t ) : return = match Stack . pop stack with | Some ( Expr ( t1 , t2 ) , stack ) -> insert_rec env stack t1 t2 | Some ( Var ( v , t ) , stack ) -> insert_var env stack v t | None -> Done match t1 , t2 with | _ when t1 == t2 -> process_stack env stack | Type . Constr ( p1 , arg... |
let insert env t u : return = insert_rec env Stack . empty t u |
let insert_var env x ty : return = insert_var env Stack . empty x ty |
let insert_tuple_solution env sol = let exception Bail of return in try let f ( k , v ) = match insert_var env k ( ACTerm . as_tuple ( Env . tyenv env ) v ) with | Done -> ( ) | r -> raise ( Bail r ) in sol f ; Done with | Bail r -> r |
let rec solve_tuple_problems env0 = let rec pop_all_tuples acc env = match Env . pop_tuple env with | None -> acc | Some pb -> pop_all_tuples ( pb :: acc ) env in AC . solve env0 @@ pop_all_tuples [ ] env0 |> Iter . flat_map ( try_with_solution env0 insert_tuple_solution ) let potentials = [ ( fun env ( ) -> Env . push... |
let unifiers ( tyenv : Type . Env . t ) t1 t2 : Subst . t Iter . t = let orig_vars = Variable . Set . ( union ( of_iter @@ Type . iter_vars t1 ) ( of_iter @@ Type . iter_vars t2 ) ) in let env0 = Env . make ~ tyenv ~ orig_vars in debug ( fun m -> m { [ |@< v > Unify :@ " % a " @ " % a " ] } @| Type . pp t1 Type . pp t2... |
let unify ( env : Type . Env . t ) t1 t2 = Iter . min ~ lt : Subst . lt @@ unifiers env t1 t2 |
let unifiable ( env : Type . Env . t ) t1 t2 = not @@ Iter . is_empty @@ unifiers env t1 t2 |
type ord = | Uncomparable | Smaller | Bigger | Equal |
let compare env t1 t2 = let b1 = unifiable env ( Type . freeze_variables env t1 ) t2 and b2 = unifiable env t1 ( Type . freeze_variables env t2 ) in match b1 , b2 with | true , true -> Equal | false , false -> Uncomparable | true , false -> Smaller | false , true -> Bigger |
module type Monad = sig type ' a m val return : ' a -> ' a m val bind : ' a m -> ( ' a -> ' b m ) -> ' b m end |
module type Extend = sig type ' a m val fmap : ( ' a -> ' b ) -> ' a m -> ' b m end |
module Extend ( M : Monad ) : Extend with type ' a m := ' a M . m = struct open M let fmap f m = bind m ( fun a -> return ( f a ) ) end |
module Option = struct type ' a t = ' a option module Monad = struct type ' a m = ' a t let return x = Some x let bind m f = match m with | None -> None | Some a -> f a end include Monad include Extend ( Monad ) end |
module type Monad2 = sig type ( ' a , ' x ) m val return : ' a -> ( ' a , ' x ) m val bind : ( ' a , ' x ) m -> ( ' a -> ( ' b , ' x ) m ) -> ( ' b , ' x ) m end |
module Extend2 ( M : Monad2 ) : sig open M val fmap : ( ' a -> ' b ) -> ( ' a , ' x ) m -> ( ' b , ' x ) m include M let fmap f m = bind m ( fun a -> return ( f a ) ) end |
module Result = struct type ( ' a , ' err ) t = Ok of ' a | Error of ' err module Monad = struct type ( ' a , ' err ) m = ( ' a , ' err ) t let return x = Ok x let bind m f = match m with | Error e -> Error e | Ok a -> f a end include Monad include Extend2 ( Monad ) end |
module Option ' = struct type ' a t = ' a option module Monad = struct type ( ' a , _ ) m = ' a t let return x = Some x let bind m f = match m with | None -> None | Some a -> f a end include Monad include ( Extend2 ( Monad ) : Extend with type ' a m := ' a t ) end |
module Make ( D : Debugger . S_base ) = struct include D module Value = struct type t = | Exists_on_target of Obj . t | Synthetic_ptr of Synthetic_ptr . t let create_exists_on_target obj = Exists_on_target obj let create_synthetic_ptr ptr = Synthetic_ptr ptr let is_block t = match t with | Exists_on_target obj -> Obj .... |
module type STRUCTURE = sig type ' a structure val map : ( ' a -> ' b ) -> ' a structure -> ' b structure val iter : ( ' a -> unit ) -> ' a structure -> unit exception Iter2 val iter2 : ( ' a -> ' b -> unit ) -> ' a structure -> ' b structure -> unit end |
module Make ( S : STRUCTURE ) = struct |
type ' a structure = ' a S . structure |
type variable = descriptor UnionFind . point id : int ; structure : variable structure option ; mutable mark : Mark . t ; } |
let id v = ( UnionFind . get v ) . id |
let structure v = ( UnionFind . get v ) . structure |
let fresh = let c = ref 0 in fun structure -> let id = Misc . postincrement c in let mark = Mark . none in UnionFind . fresh { id ; structure ; mark } |
let occurs_check x y = let black = Mark . fresh ( ) in let rec visit z = let desc = UnionFind . get z in if not ( Mark . same desc . mark black ) then begin desc . mark <- black ; if UnionFind . equivalent x z then raise ( Occurs ( x , y ) ) else Option . iter ( S . iter visit ) desc . structure end in visit y |
let rec unify ( v1 : variable ) ( v2 : variable ) : unit = if not ( UnionFind . equivalent v1 v2 ) then begin let desc1 = UnionFind . get v1 and desc2 = UnionFind . get v2 in let desc = match desc1 . structure , desc2 . structure with | None , None -> desc1 | None , Some _ -> occurs_check v1 v2 ; desc2 | Some _ , None ... |
let unify v1 v2 = try unify v1 v2 with S . Iter2 -> raise ( Unify ( v1 , v2 ) ) |
type term = | TVar of int | TNode of term structure |
let rec decode ( v : variable ) : term = match structure v with | None -> TVar ( id v ) | Some t -> TNode ( S . map decode t ) end |
module Trusted : sig type ' a t val empty : ' a t val unsafe_create_uninitialized : len : int -> ' a t val create_obj_array : len : int -> ' a t val create : len : int -> ' a -> ' a t val singleton : ' a -> ' a t val get : ' a t -> int -> ' a val set : ' a t -> int -> ' a -> unit val swap : _ t -> int -> int -> unit va... |
let invariant t = assert ( Caml . Obj . tag ( Caml . Obj . repr t ) <> Caml . Obj . double_array_tag ) |
let init l ~ f = if l < 0 then invalid_arg " Uniform_array . init " else ( let res = unsafe_create_uninitialized ~ len : l in for i = 0 to l - 1 do unsafe_set res i ( f i ) done ; res ) ; ; |
let of_array arr = init ~ f ( : Array . unsafe_get arr ) ( Array . length arr ) |
let map a ~ f = init ~ f ( : fun i -> f ( unsafe_get a i ) ) ( length a ) |
let mapi a ~ f = init ~ f ( : fun i -> f i ( unsafe_get a i ) ) ( length a ) |
let iter a ~ f = for i = 0 to length a - 1 do f ( unsafe_get a i ) done ; ; |
let iteri a ~ f = for i = 0 to length a - 1 do f i ( unsafe_get a i ) done ; ; |
let foldi a ~ init ~ f = let acc = ref init in for i = 0 to length a - 1 do acc := f i ! acc ( unsafe_get a i ) done ; ! acc ; ; |
let to_list t = List . init ~ f ( : get t ) ( length t ) |
let of_list l = let len = List . length l in let res = unsafe_create_uninitialized ~ len in List . iteri l ~ f ( : fun i x -> set res i x ) ; res ; ; |
let to_array t = Array . init ( length t ) ~ f ( : fun i -> unsafe_get t i ) |
let exists t ~ f = let rec loop t ~ f i = if i < 0 then false else f ( unsafe_get t i ) || loop t ~ f ( i - 1 ) in loop t ~ f ( length t - 1 ) ; ; |
let for_all t ~ f = let rec loop t ~ f i = if i < 0 then true else f ( unsafe_get t i ) && loop t ~ f ( i - 1 ) in loop t ~ f ( length t - 1 ) ; ; |
let map2_exn t1 t2 ~ f = let len = length t1 in if length t2 <> len then invalid_arg " Array . map2_exn " ; init len ~ f ( : fun i -> f ( unsafe_get t1 i ) ( unsafe_get t2 i ) ) ; ; |
let t_sexp_grammar ( type elt ) ( grammar : elt Sexplib0 . Sexp_grammar . t ) : elt t Sexplib0 . Sexp_grammar . t = Sexplib0 . Sexp_grammar . coerce ( Array . t_sexp_grammar grammar ) ; ; include Sexpable . Of_sexpable1 ( Array ) ( struct type nonrec ' a t = ' a t let to_sexpable = to_array let of_sexpable = of_array e... |
let fold t ~ init ~ f = let r = ref init in for i = 0 to length t - 1 do r := f ! r ( unsafe_get t i ) done ; ! r ; ; |
let min_elt t ~ compare = Container . min_elt ~ fold t ~ compare |
let max_elt t ~ compare = Container . max_elt ~ fold t ~ compare |
let compare compare_elt a b = if phys_equal a b then 0 else ( let len_a = length a in let len_b = length b in let ret = compare len_a len_b in if ret <> 0 then ret else ( let rec loop i = if i = len_a then 0 else ( let l = unsafe_get a i and r = unsafe_get b i in let res = compare_elt l r in if res <> 0 then res else l... |
type ( ' a , ' b ) ' b term = | Term of ' a * ( ' a , ' b ) ' b term list | Var of ' b |
let print_term ( t ( : string , string ) string term ) term = print_string ^$ string_of_sexp ^$ sexp_of_term sexp_of_string sexp_of_string t |
type ( ' a , ' b ) ' b delta = ( ' b * ( ' a , ' b ) ' b term ) term list |
let rec robOccursCheck ( x : ' a ) ' a ( ts : ( ' b , ' a ) ' a term list ) list ( delta : ( ' b , ' a ) ' a delta ) delta = match ts with | [ ] -> true | h :: t -> ( match h with && robOccursCheck x t delta |
let subst_r ( x ( : ' a , ' b ) ' bterm ) ' bterm ( delta ( : ' a , ' b ) ' b delta ) delta : ( ' a , ' b ) ' bterm = let cur = ref x in ( try while true do match ! cur with done with Not_found -> ( ) ) ; ! cur |
let rec subst ( x , s ) s t = match t with | Var x ' -> if x = x ' then s else t | Term ( f , ls ) ls -> Term ( Termf , List . map ( subst ( x , s ) s ) s ls ) |
let rob ( sts : ( ( ' a , ' b ) ' b term * ( ' a , ' b ) ' b term ) term list ) list : ( ' a , ' b ) ' b delta option = let rec aux sts acc : ( ' a , ' b ) ' b delta = ( match sts with | [ ] -> acc | ( ox , oy ) oy :: t -> ( match x , y with try let res = aux sts [ ] in Some res with Not_found -> None |
let term , term_eoi = MGram . Entry . mk " term " , MGram . Entry . mk " term_eoi " |
let pair = MGram . Entry . mk " pair " |
let _ = begin MGram . Entry . clear term ; MGram . Entry . clear term_eoi ; MGram . Entry . clear pair ; EXTEND MGram GLOBAL : term term_eoi pair ; term_eoi : [ [ t = term ; EOI -> t ] ] ; term : [ [ f = LIDENT ; ( " " ; terms = LIST0 SELF SEP " , " ; ) " " -> Term ( Termf , terms ) terms | f = LIDENT -> Term ( f [ ] )... |
let term_of_string = MGram . parse_string term_eoi ( Loc . mk " < string ) " > |
let pair_of_string = MGram . parse_string pair ( Loc . mk " < pair ) " > |
type _ succ = Succ |
type _ nat = | NZ : zero nat | NS : ' a nat -> ' a succ nat |
type _ fin = | FZ : ' a succ fin | FS : ' a fin -> ' a succ fin |
type _ is_succ = IS : ' a succ is_succ |
let fin_succ : type n . n fin -> n is_succ = function | FZ -> IS | FS _ -> IS ; ; [ %% expect { | |
type _ succ = Succ |
type _ nat = NZ : zero nat | NS : ' a nat -> ' a succ nat |
type _ fin = FZ : ' a succ fin | FS : ' a fin -> ' a succ fin |
type _ is_succ = IS : ' a succ is_succ } ] ; ; | |
type ' a term = | Var of ' a fin | Leaf | Fork of ' a term * ' a term |
let var x = Var x |
let lift r : ' m fin -> ' n term = fun x -> Var ( r x ) |
let rec pre_subst f = function | Var x -> f x | Leaf -> Leaf | Fork ( t1 , t2 ) -> Fork ( pre_subst f t1 , pre_subst f t2 ) |
let comp_subst f g ( x : ' a fin ) = pre_subst f ( g x ) ; ; [ %% expect { | |
type ' a term = Var of ' a fin | Leaf | Fork of ' a term * ' a term ( ' b fin -> ' c term ) -> ( ' a fin -> ' b term ) -> ' a fin -> ' c term = < fun > } ] ; ; | |
let rec thin : type n . n succ fin -> n fin -> n succ fin = fun x y -> match x , y with | FZ , y -> FS y | FS x , FZ -> FZ | FS x , FS y -> FS ( thin x y ) [ %% expect { | } ] ; ; | |
let bind t f = match t with | None -> None | Some x -> f x [ %% expect { | } ] ; ; | |
let rec thick : type n . n succ fin -> n succ fin -> n fin option = fun x y -> match x , y with | FZ , FZ -> None | FZ , FS y -> Some y | FS x , FZ -> let IS = fin_succ x in Some FZ | FS x , FS y -> let IS = fin_succ x in bind ( thick x y ) ( fun x -> Some ( FS x ) ) [ %% expect { | } ] ; ; | |
let rec check : type n . n succ fin -> n succ term -> n term option = fun x t -> match t with | Var y -> bind ( thick x y ) ( fun x -> Some ( Var x ) ) | Leaf -> Some Leaf | Fork ( t1 , t2 ) -> bind ( check x t1 ) ( fun t1 -> bind ( check x t2 ) ( fun t2 -> Some ( Fork ( t1 , t2 ) ) ) ) [ %% expect { | } ] ; ; | |
let subst_var x t ' y = match thick x y with | None -> t ' | Some y ' -> Var y ' [ %% expect { | } ] ; ; | |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.