text
stringlengths
0
601k
type located_sentence = Positions . positions * sentence
let or_comment_iter f = function | Thing s -> f s | Comment _ -> ( )
let or_comment_fold f accu = function | Thing s -> f accu s | Comment _ -> accu
let or_comment_map f = function | Thing s -> Thing ( f s ) | Comment c -> Comment c
let or_comment_filter_map f = function | Thing s -> Some ( f s ) | Comment _ -> None
let or_comment_count accu = function | Thing _ -> accu + 1 | Comment _ -> accu
let count_things ( xs : ' a or_comment list ) = List . fold_left or_comment_count 0 xs
let make_key name sexp_of = let name = " sentry_ " ^ name in Univ_map . Key . create ~ name sexp_of ; ;
let dsn_key = make_key " dsn " [ % sexp_of : Dsn . t ]
let context_key = make_key " context " [ % sexp_of : Context . t ]
let with_thread_local key value f = Scheduler . with_local key ( Some value ) ~ f
let with_dsn value f = with_thread_local dsn_key value f
let with_context value f = with_thread_local context_key value f
let default_context = lazy ( Context . default ( ) )
let find_context ( ) = Scheduler . find_local context_key |> function | Some context -> context | None -> Lazy . force default_context ; ;
let with_new_context ? tags f = let context = find_context ( ) |> Context . copy in with_context context ( fun ( ) -> Option . iter tags ~ f ( : fun tags -> Context . merge_tags tags context ) ; f context ) ; ;
let set_environment env = ( find_context ( ) ) . environment <- Some env
let set_server_name name = ( find_context ( ) ) . server_name <- Some name
let set_release release = ( find_context ( ) ) . release <- Some release
let merge_tags tags = find_context ( ) |> Context . merge_tags tags
let add_breadcrumb crumb = find_context ( ) |> Context . add_breadcrumb crumb
let make_event ? tags ? exn ? message ( ) = let context = find_context ( ) in let exn = Option . map exn ~ f : List . return in Event . make ? exn ? message ~ context ? tags ( ) ; ;
let capture_event ? tags ? exn ? message ( ) = let dsn = Scheduler . find_local dsn_key |> Option . value ~ default : Dsn . default in match dsn with | Some dsn -> let event = make_event ? tags ? exn ? message ( ) in Log . Global . info " Uploading sentry event % s " ( Uuid . unwrap event . event_id ) ; Client . send_e...
let capture_message ? tags message = let message = Message . make ~ message ( ) in capture_event ? tags ~ message ( ) ; ;
let capture_exception ? tags ? message exn = let exn = Exception . of_exn exn in let message = Option . map message ~ f ( : fun message -> Message . make ~ message ( ) ) in capture_event ? tags ? message ~ exn ( ) ; ;
let capture_error ? tags err = let exn = Exception . of_error err in let message = Message . make ~ message ( : Error . to_string_hum err ) ( ) in capture_event ? tags ~ message ~ exn ( ) ; ;
let with_exn_handler f = try f ( ) with | e -> let backtrace = Caml . Printexc . get_raw_backtrace ( ) in capture_exception e ; Caml . Printexc . raise_with_backtrace e backtrace ; ;
let with_exn_handler_ignore f = try f ( ) with | e -> capture_exception e ; ;
let capture_and_return_or_error v = match v with | Ok _ -> v | Error e -> capture_error e ; v ; ;
let with_error_and_exn_handler f = with_exn_handler ( fun ( ) -> f ( ) |> capture_and_return_or_error ) ; ;
let with_async_exn_handler f = Monitor . try_with ~ extract_exn : false ~ rest ( ` : Call capture_exception ) f >>= function | Ok res -> return res | Error e -> let backtrace = Caml . Printexc . get_raw_backtrace ( ) in capture_exception e ; Caml . Printexc . raise_with_backtrace e backtrace ; ;
let with_async_exn_handler_ignore f = Monitor . handle_errors f capture_exception
let with_async_error_and_exn_handler f = with_async_exn_handler ( fun ( ) -> f ( ) >>| capture_and_return_or_error ) ; ;
type ' + a node = | Nil | Cons of ' a * ' a t
let empty ( ) = Nil
let return x ( ) = Cons ( x , empty )
let rec map f seq ( ) = match seq ( ) with | Nil -> Nil | Cons ( x , next ) -> Cons ( f x , map f next )
let rec filter_map f seq ( ) = match seq ( ) with | Nil -> Nil | Cons ( x , next ) -> match f x with | None -> filter_map f next ( ) | Some y -> Cons ( y , filter_map f next )
let rec filter f seq ( ) = match seq ( ) with | Nil -> Nil | Cons ( x , next ) -> if f x then Cons ( x , filter f next ) else filter f next ( )
let rec flat_map f seq ( ) = match seq ( ) with | Nil -> Nil | Cons ( x , next ) -> flat_map_app f ( f x ) next ( ) | Nil -> flat_map f tail ( ) | Cons ( x , next ) -> Cons ( x , flat_map_app f next tail )
let fold_left f acc seq = let rec aux f acc seq = match seq ( ) with | Nil -> acc | Cons ( x , next ) -> let acc = f acc x in aux f acc next in aux f acc seq
let iter f seq = let rec aux seq = match seq ( ) with | Nil -> ( ) | Cons ( x , next ) -> f x ; aux next in aux seq
module M = struct foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; foo bar ; fo...
type product = < host : Ketrew_pure . Host . t ; is_done : Ketrew_pure . Target . Condition . t option ; class1_path : string ; class2_path : string ; class1_expression_path : string ; class2_expression_path : string ; work_dir_path : string >
let move_seq2hla_product ? host ~ path s = let host = match host with | None -> s # host | Some h -> h in let tp p = let base = String . chop_prefix_exn ~ prefix : s # work_dir_path p in path // base in let class1 = KEDSL . single_file ~ host ( tp s # class1_path ) in let class2 = KEDSL . single_file ~ host ( tp s # cl...
let hla_type ~ work_dir ~ run_with ~ r1 ~ r2 ~ run_name : product KEDSL . workflow_node = let tool = Machine . get_tool run_with Machine . Tool . Default . seq2hla in let name = sprintf " seq2HLA -% s " run_name in let host = Machine . as_host run_with in let processors = Machine . max_processors run_with in let make =...
module Enc : sig type t type state val create : Var_store . t -> input_size : int -> hidden_size : int -> t val forward : t -> Tensor . t -> hidden : state -> state * Tensor . t val zero_state : t -> state val to_tensor : state -> Tensor . t type state = Layer . Gru . state type t = ( Tensor . t -> hidden : state -> st...
type ' state decode_fn = Tensor . t -> hidden ' : state -> enc_outputs : Tensor . t -> is_training : bool -> ' state * Tensor . t
module type Decoder = sig type t type state val create : Var_store . t -> hidden_size : int -> output_size : int -> t val forward : t -> state decode_fn val zero_state : t -> state val of_tensor : Tensor . t -> state end
module Dec : Decoder = struct type state = Layer . Gru . state type t = state decode_fn * state let create vs ~ hidden_size ~ output_size = let embedding = Layer . embeddings vs ~ num_embeddings : output_size ~ embedding_dim : hidden_size in let gru = Layer . Gru . create vs ~ input_dim : hidden_size ~ hidden_size in l...
module Dec_attn : Decoder = struct type state = Layer . Gru . state type t = state decode_fn * state let create vs ~ hidden_size ~ output_size = let device = Var_store . device vs in let embedding = Layer . embeddings vs ~ num_embeddings : output_size ~ embedding_dim : hidden_size in let gru = Layer . Gru . create vs ~...
let predict ~ input_ ~ enc ~ dec ~ dec_start ~ dec_eos ~ device = let enc_final , enc_outputs = List . fold_map input_ ~ init ( : Enc . zero_state enc ) ~ f ( : fun state idx -> let input_tensor = Tensor . of_int1 [ | idx ] | ~ device in Enc . forward enc input_tensor ~ hidden : state ) in let enc_outputs = Tensor . st...
let train_loss ~ input_ ~ target ~ enc ~ dec ~ dec_start ~ dec_eos ~ device = let enc_final , enc_outputs = List . fold_map input_ ~ init ( : Enc . zero_state enc ) ~ f ( : fun state idx -> let input_tensor = Tensor . of_int1 [ | idx ] | ~ device in Enc . forward enc input_tensor ~ hidden : state ) in let enc_outputs =...
module Loss_stats = struct type t = { mutable total_loss : float ; mutable samples : int } let create ( ) = { total_loss = 0 . ; samples = 0 } let avg_and_reset t = let avg = t . total_loss . / Float . of_int t . samples in t . total_loss <- 0 . ; t . samples <- 0 ; avg let update t loss = t . total_loss <- t . total_l...
let ( ) = let dataset = Dataset . create ~ input_lang " : eng " ~ output_lang " : fra " ~ max_length |> Dataset . reverse in let ilang = Dataset . input_lang dataset in let olang = Dataset . output_lang dataset in Stdio . printf " Input : % s % d words . \ n " %! ( Lang . name ilang ) ( Lang . length ilang ) ; Stdio . ...
module R = struct type deque = { mutable top : int ; mutable bottom : int ; data : int array ; } let default = - 1 let create ( ) = let top = 0 and bottom = 0 and data = Array . make bound default in { top ; bottom ; data } let push deque x = assert ( deque . bottom < bound ) ; deque . data . ( deque . bottom ) <- x ; ...
let stack = declare_abstract_type ( )
let ( ) = let spec = unit ^> stack in declare " create " spec R . create C . create ; let spec = stack ^> element ^> unit in declare " push " spec R . push C . push ; let spec = stack ^!> element in declare " pop " spec R . pop C . pop ; let spec = stack ^!> element in declare " steal " spec R . steal C . steal
let ( ) = let fuel = bound in main fuel
let shift_phred_scores ( ~ run_with : Machine . t ) ( ? output_postfix " . = phred33 . fastq " ) ~ input_fastq ~ output_folder = let open KEDSL in let seqtk = Machine . get_tool run_with Machine . Tool . Default . seqtk in let output_path rpath = let fqr_basename = rpath |> Filename . basename |> Filename . chop_extens...
module type DataTypes = sig type t val t_typ : t Ctypes . typ end
module Make ( Data : DataTypes ) = struct type sequence = unit ptr let sequence : sequence typ = ptr void type data = Data . t let data = Data . t_typ module GDestroy_notify = GCallback . GDestroyNotify . Make ( struct type t = data let t_typ = data end ) let create = foreign " g_sequence_new " ( GDestroy_notify . funp...
type ( ' s , ' a ) unfolder = { unfold : ' r . ' s -> on_done ' : r -> on_skip ( ' : s -> ' r ) -> on_yield ( ' : s -> ' a -> ' r ) -> ' r }
type _ t = | Sequence : ( ' s * ( ' s , ' a ) unfolder ) -> ' a t
let map ( Sequence ( s , { unfold } ) ) ~ f = Sequence ( s , { unfold = fun s ~ on_done ~ on_skip ~ on_yield -> let on_yield s a = on_yield s ( f a ) in unfold s ~ on_done ~ on_skip ~ on_yield } )
let filter ( Sequence ( s , { unfold } ) ) ~ f = Sequence ( s , { unfold = fun s ~ on_done ~ on_skip ~ on_yield -> let on_yield s a = if f a then on_yield s a else on_skip s in unfold s ~ on_done ~ on_skip ~ on_yield } )
let fold_1 ( Sequence ( s , { unfold } ) ) ~ init ~ f = let rec loop s v = unfold s ~ on_done : v ~ on_skip ( : fun s -> loop s v ) ~ on_yield ( : fun s a -> loop s ( f v a ) ) in loop s init
let fold_2 ( Sequence ( s , { unfold } ) ) ~ init ~ f = let s_ref = ref s in let v_ref = ref init in while begin unfold ! s_ref ~ on_done : false ~ on_skip ( : fun s -> s_ref := s ; true ) ~ on_yield : ( fun s a -> s_ref := s ; v_ref := f ! v_ref a ; true ) end do ( ) done ; ! v_ref
let ( ) |> x f = f x
let r = ref 0
let true_effect ( ) = incr r ; print_int ! r ; print_char ' ' ; true
let false_effect ( ) = incr r ; print_int ! r ; print_char ' ' ; false
let test i f = print_int i ; print_string " : " ; print_endline ( string_of_bool ( f ( ) ) )
let s = Bytes . of_string " \ 000 "
let ( ) = Bytes . set s 0 ' \ 001 '
let unknown_true = Bytes . get s 0 = ' \ 001 '
let unknown_false = Bytes . get s 0 <> ' \ 001 '
let ( ) = test 1 ( fun ( ) -> true || true ) ; test 2 ( fun ( ) -> true || false ) ; test 3 ( fun ( ) -> true || true_effect ( ) ) ; test 4 ( fun ( ) -> true || false_effect ( ) ) ; test 5 ( fun ( ) -> true || unknown_true ) ; test 6 ( fun ( ) -> true || unknown_false ) ; test 7 ( fun ( ) -> false || true ) ; test 8 ( ...
module type NAMED = sig type t val name : string end
module type S = sig module Param : module type of Param module Lit : module type of Lit module Expr : module type of Expr module Table : module type of Table module Field : module type of Field module Vector : module type of Vector module Select : Select . S module Insert : Insert . S module Replace : Replace . S modul...
module Make ( D : Driver . S ) : S with type ' t Table . t = ' t Table . t and type ( ' t , ' a ) Field . t = ( ' t , ' a ) Field . t and type ( ' t1 , ' t2 ) Field . foreign_key = ( ' t1 , ' t2 ) Field . foreign_key and type ' a Lit . t = ' a Lit . t and type ' a Expr . t = ' a Expr . t and type ' a Expr . cast = ' a ...
type state = { tables : string list ref ; references : ( string * string , string * string ) Hashtbl . t }
let global_references = ref None
let load_state ( ) = match ! global_references with | Some references -> Some { tables = ref [ ] ; references } | None -> None
let error loc msg = raise @@ Location . Error ( Location . error ~ loc msg )
let construct s = Exp . construct ( lid s )
let there = construct " There " None
let skip x = construct " Skip " ( Some x )
let rec snoc y = function | [ ] -> [ y ] | x :: xs -> x ( :: snoc y xs )
let rec build_steps = function | 0 -> there | n -> skip ( build_steps ( n - 1 ) )
let index loc v l = let rec idx acc = function | [ ] -> error loc ( sprintf " index for % s not found " v ) | x :: xs -> if x = v then acc else idx ( acc + 1 ) xs in idx 0 l
let find_reference loc refs ref = try Hashtbl . find refs ref with Not_found -> error loc ( sprintf " reference for % s . % s not found " ( fst ref ) ( snd ref ) )
module StringSet = Set . Make ( struct type t = string let compare = compare end )
let rec map_expr_list loc f = function | { pexp_desc = Pexp_construct ( { txt = Lident " " :: } as cons , Some ( { pexp_desc = Pexp_tuple [ expr ; rest ] ; pexp_loc } as args ) ) } as e -> let l = [ f pexp_loc expr ; map_expr_list pexp_loc f rest ] in { e with pexp_desc = Pexp_construct ( cons , Some { args with pexp_d...
let add_table t u ts = let rec add = function | [ ] -> t ::! ts | x :: xs -> if x = u then t :: x :: xs else x :: add xs in ts := add ! ts
let rec map_query st loc = function | { pexp_desc = Pexp_let ( rec_flag , [ { pvb_expr } as b ] , ( { pexp_loc } as expr ) ) } -> let e = map_query st loc pvb_expr in let binding = { b with pvb_expr = e } in let expr = map_query st pexp_loc expr in Exp . let_ rec_flag [ binding ] expr | { pexp_desc = Pexp_extension ( {...
let rec map_module table references loc = function | [ ] -> ( ) | { pstr_desc = Pstr_value ( _ , [ { pvb_pat = { ppat_desc = Ppat_var { txt = field } } ; pvb_expr = { pexp_desc = Pexp_apply ( { pexp_desc = Pexp_ident { txt = Ldot ( Lident " Field " , " foreign_key " ) } } , [ ( Nolabel , { pexp_desc = Pexp_constant ( P...
let sql_mapper references _config _cookies = { default_mapper with expr = ( fun mapper expr -> match expr with | { pexp_desc = Pexp_extension ( { txt = " sql " ; loc } , pstr ) } -> begin match pstr with | PStr [ { pstr_desc = Pstr_eval ( expr , _ ) } ] -> let expr = match load_state ( ) with | Some st -> map_query st ...
let migration = Versions . migrate Versions . ocaml_404 Versions . ocaml_current
let ( ) = let references = Hashtbl . create 16 in Driver . register ~ name " : ppx_sequoia " Versions . ocaml_404 ( sql_mapper references )