text stringlengths 0 601k |
|---|
let extra_args t id = match Id . Map . find id t . extra_args with | exception Not_found -> if not ( Bound_parameters . is_empty t . used_extra_params ) then Misc . fatal_errorf " This [ Apply_cont_rewrite ] does not have any @ extra arguments for use \ ID % a , but it has @ >= 1 extra parameter :@ % a " Id . print id ... |
let original_params_arity t = Bound_parameters . arity_with_subkinds ( original_params t ) |
module type Model = sig type t val cutoff : t -> t -> bool end |
module type Action = sig type t [ @@ deriving sexp_of ] end |
module type State = sig type t end |
module type S = sig module Model : Model module Action : Action module State : State val on_startup : schedule_action ( : Action . t -> unit ) -> Model . t -> State . t Deferred . t Component . create ~ apply_action model view ; ; ] } The full code for this example can be found in examples / counter . ) * val create : ... |
module Private = struct type ( ' state , ' model , ' action ) snapshot = { view : Vdom . Node . t ; apply_action : ' state -> schedule_event ( : unit Ui_effect . t -> unit ) -> ' model -> ' action -> ' model ; update_visibility : ' model -> schedule_event ( : unit Ui_effect . t -> unit ) -> ' model ; on_display : ' sta... |
type t = { size : Dwarf_int . t ; values : Dwarf_value . t list } |
let create ~ start_of_code_symbol ~ end_of_code_symbol ~ debug_info_label = let module V = Dwarf_value in let values = [ V . int16 ~ comment " : section version number " ( Int16 . of_int_exn 2 ) ; V . offset_into_debug_info ~ comment " : offset to compilation unit header " debug_info_label ; V . int8 ~ comment " : Dwar... |
let size t = t . size |
let emit ~ asm_directives t = Initial_length . emit ~ asm_directives ( Initial_length . create t . size ) ; List . iter ( fun v -> Dwarf_value . emit ~ asm_directives v ) t . values |
let pic_code = ref true |
let command_line_options = [ " - fPIC " , Arg . Set pic_code , " Generate position - independent machine code ( default ) " ; " - fno - PIC " , Arg . Clear pic_code , " Generate position - dependent machine code " ] |
type specific_operation = Imultaddf | Imultsubf |
type addressing_mode = | Iindexed of int | Iindexed2 of int |
let identity_addressing = Iindexed 0 |
let offset_addressing addr delta = match addr with | Iindexed n -> Iindexed ( n + delta ) | Iindexed2 n -> Iindexed2 ( n + delta ) |
let num_args_addressing = function | Iindexed _ -> 1 | Iindexed2 _ -> 2 |
let print_addressing printreg addr ppf arg = match addr with | Iindexed n -> let idx = if n <> 0 then Printf . sprintf " + % i " n else " " in fprintf ppf " % a % s " printreg arg . ( 0 ) idx | Iindexed2 n -> let idx = if n <> 0 then Printf . sprintf " + % i " n else " " in fprintf ppf " % a + % a % s " printreg arg . ... |
let print_specific_operation printreg op ppf arg = match op with | Imultaddf -> fprintf ppf " % a * f % a + f % a " printreg arg . ( 0 ) printreg arg . ( 1 ) printreg arg . ( 2 ) | Imultsubf -> fprintf ppf " % a * f % a - f % a " printreg arg . ( 0 ) printreg arg . ( 1 ) printreg arg . ( 2 ) |
let operation_is_pure _ = true |
let operation_can_raise _ = false |
type anon_fun = ( string -> unit ) |
type spec = | Unit of ( unit -> unit ) | Bool of ( bool -> unit ) | Set of bool ref | Clear of bool ref | String of ( string -> unit ) | Set_string of string ref | Int of ( int -> unit ) | Set_int of int ref | Float of ( float -> unit ) | Set_float of float ref | Tuple of spec list | Symbol of string list * ( string ->... |
type error = | Unknown of string | Wrong of string * string * string | Missing of string | Message of string |
let rec assoc3 x l = match l with | [ ] -> raise Not_found | ( y1 , y2 , _ ) :: _ when y1 = x -> y2 | _ :: t -> assoc3 x t |
let split s = let i = String . index s ' ' = in let len = String . length s in String . sub s 0 i , String . sub s ( i + 1 ) ( len ( - i + 1 ) ) |
let make_symlist prefix sep suffix l = match l with | [ ] -> " < none " > | h :: t -> ( List . fold_left ( fun x y -> x ^ sep ^ y ) ( prefix ^ h ) t ) ^ suffix |
let print_spec buf ( key , spec , doc ) = if String . length doc > 0 then match spec with | Symbol ( l , _ ) -> bprintf buf " % s % s % s \ n " key ( make_symlist " { " " " | " } " l ) doc | _ -> bprintf buf " % s % s \ n " key doc |
let help_action ( ) = raise ( Stop ( Unknown " - help " ) ) |
let add_help speclist = let add1 = try ignore ( assoc3 " - help " speclist ) ; [ ] with Not_found -> [ " - help " , Unit help_action , " Display this list of options " ] and add2 = try ignore ( assoc3 " -- help " speclist ) ; [ ] with Not_found -> [ " -- help " , Unit help_action , " Display this list of options " ] in... |
let usage_b buf speclist errmsg = bprintf buf " % s \ n " errmsg ; List . iter ( print_spec buf ) ( add_help speclist ) |
let usage_string speclist errmsg = let b = Buffer . create 200 in usage_b b speclist errmsg ; Buffer . contents b |
let usage speclist errmsg = eprintf " % s " ( usage_string speclist errmsg ) |
let current = ref 0 |
let bool_of_string_opt x = try Some ( bool_of_string x ) with Invalid_argument _ -> None |
let int_of_string_opt x = try Some ( int_of_string x ) with Failure _ -> None |
let float_of_string_opt x = try Some ( float_of_string x ) with Failure _ -> None |
let parse_and_expand_argv_dynamic_aux allow_expand current argv speclist anonfun errmsg = let initpos = ! current in let convert_error error = let b = Buffer . create 200 in let progname = if initpos < ( Array . length ! argv ) then ! argv . ( initpos ) else " ( ) " ? in begin match error with | Unknown " - help " -> (... |
let parse_and_expand_argv_dynamic current argv speclist anonfun errmsg = parse_and_expand_argv_dynamic_aux true current argv speclist anonfun errmsg |
let parse_argv_dynamic ( ? current = current ) argv speclist anonfun errmsg = parse_and_expand_argv_dynamic_aux false current ( ref argv ) speclist anonfun errmsg |
let parse_argv ( ? current = current ) argv speclist anonfun errmsg = parse_argv_dynamic ~ current : current argv ( ref speclist ) anonfun errmsg |
let parse l f msg = try parse_argv Sys . argv l f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0 |
let parse_dynamic l f msg = try parse_argv_dynamic Sys . argv l f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0 |
let parse_expand l f msg = try let argv = ref Sys . argv in let spec = ref l in let current = ref ( ! current ) in parse_and_expand_argv_dynamic current argv spec f msg with | Bad msg -> eprintf " % s " msg ; exit 2 | Help msg -> printf " % s " msg ; exit 0 |
let second_word s = let len = String . length s in let rec loop n = if n >= len then len else if s . [ n ] = ' ' then loop ( n + 1 ) else n in match String . index s ' \ t ' with | n -> loop ( n + 1 ) | exception Not_found -> begin match String . index s ' ' with | n -> loop ( n + 1 ) | exception Not_found -> len end |
let max_arg_len cur ( kwd , spec , doc ) = match spec with | Symbol _ -> max cur ( String . length kwd ) | _ -> max cur ( String . length kwd + second_word doc ) |
let replace_leading_tab s = let seen = ref false in String . map ( function ' \ t ' when not ! seen -> seen := true ; ' ' | c -> c ) s |
let add_padding len ksd = match ksd with | ( _ , _ , " " ) -> ksd | ( kwd , ( Symbol _ as spec ) , msg ) -> let cutcol = second_word msg in let spaces = String . make ( ( max 0 ( len - cutcol ) ) + 3 ) ' ' in ( kwd , spec , " \ n " ^ spaces ^ replace_leading_tab msg ) | ( kwd , spec , msg ) -> let cutcol = second_word ... |
let align ( ? limit = max_int ) speclist = let completed = add_help speclist in let len = List . fold_left max_arg_len 0 completed in let len = min len limit in List . map ( add_padding len ) completed |
let trim_cr s = let len = String . length s in if len > 0 && String . get s ( len - 1 ) = ' \ r ' then String . sub s 0 ( len - 1 ) else s |
let read_aux trim sep file = let ic = open_in_bin file in let buf = Buffer . create 200 in let words = ref [ ] in let stash ( ) = let word = Buffer . contents buf in let word = if trim then trim_cr word else word in words := word :: ! words ; Buffer . clear buf in begin try while true do let c = input_char ic in if c =... |
let read_arg = read_aux true ' \ n ' |
let read_arg0 = read_aux false ' \ x00 ' |
let write_aux sep file args = let oc = open_out_bin file in Array . iter ( fun s -> fprintf oc " % s % c " s sep ) args ; close_out oc |
let write_arg = write_aux ' \ n ' |
let write_arg0 = write_aux ' \ x00 ' |
let get_error_when_null_denominator ( ) = ! error_when_null_denominator_flag error_when_null_denominator_flag := choice ; ; |
let get_normalize_ratio ( ) = ! normalize_ratio_flag |
let get_normalize_ratio_when_printing ( ) = ! normalize_ratio_when_printing_flag normalize_ratio_when_printing_flag := choice ; ; |
let get_floating_precision ( ) = ! floating_precision |
let get_approx_printing ( ) = ! approx_printing_flag |
let arith_print_string s = print_string s ; print_string " --> " ; ; |
let arith_print_bool = function true -> print_string " ON " ; ; |
let arith_status ( ) = print_newline ( ) ; arith_print_string " Normalization during computation " ; arith_print_bool ( get_normalize_ratio ( ) ) ; print_newline ( ) ; print_string " ( returned by get_normalize_ratio ( ) ) " ; print_newline ( ) ; print_string " ( modifiable with set_normalize_ratio < your choice ) " ; ... |
type ' a t = ' a array ' a array -> int -> ' a array -> int -> int -> unit = " caml_array_blit " ' a array -> int -> int -> ' a -> unit = " caml_array_fill " |
module Floatarray = struct external create : int -> floatarray = " caml_floatarray_create " external length : floatarray -> int = " % floatarray_length " external get : floatarray -> int -> float = " % floatarray_safe_get " external set : floatarray -> int -> float -> unit = " % floatarray_safe_set " external unsafe_ge... |
let init l f = if l = 0 then [ ] || else if l < 0 then invalid_arg " Array . init " else let res = create l ( f 0 ) in for i = 1 to pred l do unsafe_set res i ( f i ) done ; res |
let make_matrix sx sy init = let res = create sx [ ] || in for x = 0 to pred sx do unsafe_set res x ( create sy init ) done ; res |
let copy a = let l = length a in if l = 0 then [ ] || else unsafe_sub a 0 l |
let append a1 a2 = let l1 = length a1 in if l1 = 0 then copy a2 else if length a2 = 0 then unsafe_sub a1 0 l1 else append_prim a1 a2 |
let sub a ofs len = if ofs < 0 || len < 0 || ofs > length a - len then invalid_arg " Array . sub " else unsafe_sub a ofs len |
let fill a ofs len v = if ofs < 0 || len < 0 || ofs > length a - len then invalid_arg " Array . fill " else unsafe_fill a ofs len v |
let blit a1 ofs1 a2 ofs2 len = if len < 0 || ofs1 < 0 || ofs1 > length a1 - len || ofs2 < 0 || ofs2 > length a2 - len then invalid_arg " Array . blit " else unsafe_blit a1 ofs1 a2 ofs2 len |
let iter f a = for i = 0 to length a - 1 do f ( unsafe_get a i ) done |
let iter2 f a b = if length a <> length b then invalid_arg " Array . iter2 : arrays must have the same length " else for i = 0 to length a - 1 do f ( unsafe_get a i ) ( unsafe_get b i ) done |
let map f a = let l = length a in if l = 0 then [ ] || else begin let r = create l ( f ( unsafe_get a 0 ) ) in for i = 1 to l - 1 do unsafe_set r i ( f ( unsafe_get a i ) ) done ; r end |
let map2 f a b = let la = length a in let lb = length b in if la <> lb then invalid_arg " Array . map2 : arrays must have the same length " else begin if la = 0 then [ ] || else begin let r = create la ( f ( unsafe_get a 0 ) ( unsafe_get b 0 ) ) in for i = 1 to la - 1 do unsafe_set r i ( f ( unsafe_get a i ) ( unsafe_g... |
let iteri f a = for i = 0 to length a - 1 do f i ( unsafe_get a i ) done |
let mapi f a = let l = length a in if l = 0 then [ ] || else begin let r = create l ( f 0 ( unsafe_get a 0 ) ) in for i = 1 to l - 1 do unsafe_set r i ( f i ( unsafe_get a i ) ) done ; r end |
let to_list a = let rec tolist i res = if i < 0 then res else tolist ( i - 1 ) ( unsafe_get a i :: res ) in tolist ( length a - 1 ) [ ] |
let rec list_length accu = function | [ ] -> accu | _ :: t -> list_length ( succ accu ) t |
let of_list = function [ ] -> [ ] || | hd :: tl as l -> let a = create ( list_length 0 l ) hd in let rec fill i = function [ ] -> a | hd :: tl -> unsafe_set a i hd ; fill ( i + 1 ) tl in fill 1 tl |
let fold_left f x a = let r = ref x in for i = 0 to length a - 1 do r := f ! r ( unsafe_get a i ) done ; ! r |
let fold_right f a x = let r = ref x in for i = length a - 1 downto 0 do r := f ( unsafe_get a i ) ! r done ; ! r |
let exists p a = let n = length a in let rec loop i = if i = n then false else if p ( unsafe_get a i ) then true else loop ( succ i ) in loop 0 |
let for_all p a = let n = length a in let rec loop i = if i = n then true else if p ( unsafe_get a i ) then loop ( succ i ) else false in loop 0 |
let for_all2 p l1 l2 = let n1 = length l1 and n2 = length l2 in if n1 <> n2 then invalid_arg " Array . for_all2 " else let rec loop i = if i = n1 then true else if p ( unsafe_get l1 i ) ( unsafe_get l2 i ) then loop ( succ i ) else false in loop 0 |
let exists2 p l1 l2 = let n1 = length l1 and n2 = length l2 in if n1 <> n2 then invalid_arg " Array . exists2 " else let rec loop i = if i = n1 then false else if p ( unsafe_get l1 i ) ( unsafe_get l2 i ) then true else loop ( succ i ) in loop 0 |
let mem x a = let n = length a in let rec loop i = if i = n then false else if compare ( unsafe_get a i ) x = 0 then true else loop ( succ i ) in loop 0 |
let memq x a = let n = length a in let rec loop i = if i = n then false else if x == ( unsafe_get a i ) then true else loop ( succ i ) in loop 0 |
let sort cmp a = let maxson l i = let i31 = i + i + i + 1 in let x = ref i31 in if i31 + 2 < l then begin if cmp ( get a i31 ) ( get a ( i31 + 1 ) ) < 0 then x := i31 + 1 ; if cmp ( get a ! x ) ( get a ( i31 + 2 ) ) < 0 then x := i31 + 2 ; ! x end else if i31 + 1 < l && cmp ( get a i31 ) ( get a ( i31 + 1 ) ) < 0 then ... |
let stable_sort cmp a = let merge src1ofs src1len src2 src2ofs src2len dst dstofs = let src1r = src1ofs + src1len and src2r = src2ofs + src2len in let rec loop i1 s1 i2 s2 d = if cmp s1 s2 <= 0 then begin set dst d s1 ; let i1 = i1 + 1 in if i1 < src1r then loop i1 ( get a i1 ) i2 s2 ( d + 1 ) else blit src2 i2 dst ( d... |
let to_seq a = let rec aux i ( ) = if i < length a then let x = unsafe_get a i in Seq . Cons ( x , aux ( i + 1 ) ) else Seq . Nil in aux 0 |
let to_seqi a = let rec aux i ( ) = if i < length a then let x = unsafe_get a i in Seq . Cons ( ( i , x ) , aux ( i + 1 ) ) else Seq . Nil in aux 0 |
let of_rev_list = function [ ] -> [ ] || | hd :: tl as l -> let len = list_length 0 l in let a = create len hd in let rec fill i = function [ ] -> a | hd :: tl -> unsafe_set a i hd ; fill ( i - 1 ) tl in fill ( len - 2 ) tl |
let of_seq i = let l = Seq . fold_left ( fun acc x -> x :: acc ) [ ] i in of_rev_list l |
let bigarray n = [ | ] | |
let test1 ( ) = let a = bigarray 12345 in Gc . full_major ( ) ; for i = 0 to Array . length a - 1 do if a . ( i ) <> 12345 + i then print_string " Test1 : error \ n " done |
let testcopy a = Array . copy a = a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.