text
stringlengths
0
601k
let all = % a } | pp_list ( all ( ) )
let cards = Array . init 9 ( fun i -> Fd . int 1 , ( i + 1 ) 1 ) 1
let ad = fun a -> Cstr . post ( Gcc . cstr ~ level : Gcc . High a cards ) cards
let solve grille = let v = Array . init 9 ( fun _ -> Fd . array 9 1 9 ) 9 in Array . iteri ( fun i vi -> Array . iteri ( fun j vij -> let c = grille i j in if c <> ' . ' then Fd . unify vij ( Char . code c - Char . code ' 0 ' ) ' 0 ' ) ' 0 ' vi ) vi v ; Array . iter ad v ; for i = 0 to 8 do ad ( Array . init 9 ( fun j ...
let _ = let f = open_in Sys . argv ( . 1 ) 1 in try while true do let l = input_line f in solve ( fun i j -> l [ . 9 * i + j ] j ) j done with End_of_file -> ( )
THEN object method log : string -> unit end
let console = ( Ocamljs . var " console " : console ) ENDIF
let make_board ( ) = let make_input ( ) = let input = ( d # createElement " input " : D . input ) in input # setAttribute " type " " text " ; input # _set_size 1 ; input # _set_maxLength 1 ; let style = input # _get_style in style # _set_border " none " ; style # _set_padding " 0px " ; let enforce_digit ( ) = match inp...
let check_board rows _ = let error i j = let cell = rows . ( i ) . ( j ) in cell # _get_style # _set_backgroundColor " # ff0000 " in let check_set set = let seen = Array . make 9 None in ArrayLabels . iter set ~ f ( : fun ( i , j ) -> let cell = rows . ( i ) . ( j ) in match cell # _get_value with | " " -> ( ) | v -> l...
let ( ) >>= = Lwt . ( ) >>= THEN
module Server = Proto_js_clnt . Lwt ( struct let with_client f = let r = string_of_int ( Random . int 38 ) in f ( Orpc_js_client . create r ) end ) ELSE
module Server = Proto_js_clnt . Lwt ( struct let with_client f = f ( Orpc_js_client . create " / sudoku " ) end ) ENDIF
let get_board rows _ = ignore ( Lwt . catch ( fun ( ) -> Server . get_board ( ) >>= fun board -> for i = 0 to 8 do for j = 0 to 8 do let cell = rows . ( i ) . ( j ) in let style = cell # _get_style in style # _set_backgroundColor " # ffffff " ; match board . ( i ) . ( j ) with | None -> cell # _set_value " " ; cell # _...
let onload ( ) = let ( rows , table ) = make_board ( ) in let check = d # getElementById " check " in check # _set_onclick ( check_board rows ) ; let new_game = d # getElementById " new_game " in new_game # _set_onclick ( get_board rows ) ; let board = d # getElementById " board " in ignore ( board # appendChild table ...
let rec arrow_typ cmts i ( { ast = typ ; _ } as xtyp ) = let ctx = Typ typ in let { ptyp_desc ; ptyp_loc ; _ } = typ in match ptyp_desc with | Ptyp_arrow ( l , t1 , t2 ) -> let before = if i > 0 then ptyp_loc else t1 . ptyp_loc in Cmts . relocate cmts ~ src : ptyp_loc ~ before ~ after : t2 . ptyp_loc ; let rest = match...
let arrow_typ cmts t = arrow_typ cmts 0 t
let rec class_arrow_typ cmts ( { ast = typ ; _ } as xtyp ) = let ctx = Cty typ in let { pcty_desc ; pcty_loc ; _ } = typ in match pcty_desc with | Pcty_arrow ( l , t1 , t2 ) -> Cmts . relocate cmts ~ src : pcty_loc ~ before : t1 . ptyp_loc ~ after : t2 . pcty_loc ; let rest = match t2 . pcty_attributes with | [ ] -> cl...
let rec or_pat ( ? allow_attribute = true ) cmts ( { ast = pat ; _ } as xpat ) = let ctx = Pat pat in match pat with | { ppat_desc = Ppat_or ( pat1 , pat2 ) ; ppat_loc ; ppat_attributes = [ ] ; _ } -> Cmts . relocate cmts ~ src : ppat_loc ~ before : pat1 . ppat_loc ~ after : pat2 . ppat_loc ; or_pat ~ allow_attribute :...
type arg_kind = | Val of arg_label * pattern xt * expression xt option | Newtypes of string loc list
let fun_ cmts ( ? will_keep_first_ast_node = true ) xexp = let rec fun_ ( ? will_keep_first_ast_node = false ) ( { ast = exp ; _ } as xexp ) = let ctx = Exp exp in let { pexp_desc ; pexp_loc ; pexp_attributes ; _ } = exp in if will_keep_first_ast_node || List . is_empty pexp_attributes then match pexp_desc with | Pexp_...
let cl_fun ( ? will_keep_first_ast_node = true ) cmts xexp = let rec fun_ ( ? will_keep_first_ast_node = false ) ( { ast = exp ; _ } as xexp ) = let ctx = Cl exp in let { pcl_desc ; pcl_loc ; pcl_attributes ; _ } = exp in if will_keep_first_ast_node || List . is_empty pcl_attributes then match pcl_desc with | Pcl_fun (...
let infix cmts prec xexp = let assoc = Option . value_map prec ~ default : Assoc . Non ~ f : Assoc . of_prec in let rec infix_ ( ? relocate = true ) xop ( ( lbl , { ast = exp ; _ } ) as xexp ) = assert ( Poly . ( lbl = Nolabel ) ) ; let ctx = Exp exp in match ( assoc , exp ) with | Left , { pexp_desc = Pexp_apply ( e0 ...
let list_pat cmts pat = let rec list_pat_ pat acc = let ctx = Pat pat in let { ppat_desc ; ppat_loc = src ; _ } = pat in match ppat_desc with | Ppat_construct ( { txt = Lident " [ ] " ; loc } , None ) -> Cmts . relocate cmts ~ src ~ before : loc ~ after : loc ; Some ( List . rev acc , loc ) | Ppat_construct ( { txt = L...
let list_exp cmts exp = let rec list_exp_ exp acc = let ctx = Exp exp in let { pexp_desc ; pexp_loc = src ; _ } = exp in match pexp_desc with | Pexp_construct ( { txt = Lident " [ ] " ; loc } , None ) -> Cmts . relocate cmts ~ src ~ before : loc ~ after : loc ; Some ( List . rev acc , loc ) | Pexp_construct ( { txt = L...
let rec ite cmts ( { ast = exp ; _ } as xexp ) = let ctx = Exp exp in let { pexp_desc ; pexp_loc ; pexp_attributes ; _ } = exp in match pexp_desc with | Pexp_ifthenelse ( cnd , thn , Some els ) -> Cmts . relocate cmts ~ src : pexp_loc ~ before : cnd . pexp_loc ~ after : els . pexp_loc ; ( Some ( sub_exp ~ ctx cnd ) , s...
let sequence cmts xexp = let rec sequence_ ( ? allow_attribute = true ) ( { ast = exp ; _ } as xexp ) = let ctx = Exp exp in let { pexp_desc ; pexp_loc ; _ } = exp in match pexp_desc with | Pexp_extension ( ext , PStr [ { pstr_desc = Pstr_eval ( ( { pexp_desc = Pexp_sequence ( e1 , e2 ) ; pexp_attributes ; _ } as exp )...
type functor_arg = Unit | Named of label option loc * module_type Ast . xt
let rec functor_type cmts ~ for_functor_kw ~ source_is_long ( { ast = mty ; _ } as xmty ) = let ctx = Mty mty in match mty with | { pmty_desc = Pmty_functor ( fp , body ) ; pmty_loc ; pmty_attributes } when for_functor_kw || ( List . is_empty pmty_attributes && not ( source_is_long mty ) ) -> let functor_arg = match fp...
let rec functor_ cmts ~ for_functor_kw ~ source_is_long ( { ast = me ; _ } as xme ) = let ctx = Mod me in match me with | { pmod_desc = Pmod_functor ( fp , body ) ; pmod_loc ; pmod_attributes } when for_functor_kw || ( List . is_empty pmod_attributes && not ( source_is_long me ) ) -> let functor_arg = match fp with | N...
let mod_with pmty = let rec mod_with_ ( { ast = me ; _ } as xme ) = let ctx = Mty me in match me with | { pmty_desc = Pmty_with ( mt , wcs ) ; pmty_attributes ; pmty_loc } -> let args , rest = mod_with_ ( sub_mty ~ ctx mt ) in ( ( wcs , pmty_loc , pmty_attributes ) :: args , rest ) | _ -> ( [ ] , xme ) in let l_rev , m...
let polynewtype cmts pat body = let ctx = Pat pat in match pat . ppat_desc with | Ppat_constraint ( pat2 , { ptyp_desc = Ptyp_poly ( pvars , _ ) ; _ } ) -> let pvars0 = pvars in let xpat = sub_pat ~ ctx pat2 in let rec polynewtype_ pvars body = let ctx = Exp body in match ( pvars , body . pexp_desc ) with | [ ] , Pexp_...
let cycle n lst = let rec loop l acc = function | 0 -> List . rev acc | k -> ( match l with | [ ] -> loop lst acc k | e :: es -> loop es ( e :: acc ) ( k - 1 ) ) in loop lst [ ] n
let array_of_symbools m n = let seeds = let f x = ` Keyword ( String . concat [ " key " ; Printf . sprintf " % 04d " x ] ) in List . map ( List . range 0 m ) ~ f : f in cycle n seeds
let hash_of_size k = let keywords = array_of_symbools k k in let values = List . map ( List . range 0 k ) ~ f ( : fun x -> ` Int ( Int64 . of_int x ) ) in ` Map ( Map . Poly . of_alist_exn ( List . zip_exn keywords values ) )
let from_timestamp f = Time . of_float f
let simple = [ ` Int ( Int64 . of_int 1 ) ; ` Int ( Int64 . of_int 2 ) ; ` Int ( Int64 . of_int 3 ) ]
let i x = ` Int ( Int64 . of_int x )
let s x = ` String x
let fl ( x : float ) = ` Float x
let mixed = [ i 0 ; i 1 ; ` Float 2 . 0 ; ` Bool true ; ` Bool false ; ` String " five " ; ` Keyword " six " ; ` Symbol " seven " ; ` String " ~ eight " ; ` Null ]
let array_nested = ` Array [ ` Array simple ; ` Array mixed ]
let list_nested = ` List [ ` List simple ; ` List mixed ]
let set_nested = ` Set ( Set . Poly . of_list [ ` Set ( Set . Poly . of_list simple ) ; ` Set ( Set . Poly . of_list mixed ) ] )
let map_simple : Transit . t = ` Map ( Map . Poly . of_alist_exn [ ` Keyword " a " , ` Int ( Int64 . of_int 1 ) ; ` Keyword " b " , ` Int ( Int64 . of_int 2 ) ; ` Keyword " c " , ` Int ( Int64 . of_int 3 ) ] )
let map_mixed : Transit . t = ` Map ( Map . Poly . of_alist_exn [ ` Keyword " a " , ` Int ( Int64 . of_int 1 ) ; ` Keyword " b " , ` String " a string " ; ` Keyword " c " , ` Bool true ] )
let map_nested : Transit . t = ` Map ( Map . Poly . of_alist_exn [ ` Keyword " simple " , map_simple ; ` Keyword " mixed " , map_mixed ] )
let small_strings = ` Array [ s " " ; s " a " ; s " ab " ; s " abc " ; s " abcd " ; s " abcde " ; s " abcdef " ]
let add_string prefix ( ` Array arr ) = ` Array ( List . map arr ~ f ( : fun ( ` String s ) -> ` String ( String . concat [ prefix ; s ] ) ) )
let uris = [ ` URI " http :// example . com " ; ` URI " ftp :// example . com " ; ` URI " file :/// path / to / file . txt " ; ` URI " http :// www . 詹姆斯 . com " ; / ]
let uuids = [ ` UUID ( Uuid . of_string " 5a2cbea3 - e8c6 - 428b - b525 - 21239370dd55 " ) ; ` UUID ( Uuid . of_string " d1dc64fa - da79 - 444b - 9fa4 - d4412f427289 " ) ; ` UUID ( Uuid . of_string " 501a978e - 3a3e - 4060 - b3be - 1cf2bd4b1a38 " ) ; ` UUID ( Uuid . of_string " b3ba141a - a776 - 48e4 - 9fae - a28ea8571...
let ints_centered_on ? range ( : m = 5 ) n = List . map ( List . range ( n - m ) ( m + n + 1 ) ) ~ f ( : fun i -> ` Int ( Int64 . of_int i ) )
let rec range f t = if Big_int . eq_big_int f t then [ ] else f :: ( range ( Big_int . add_big_int Big_int . unit_big_int f ) t )
let big_ints_centered_on m n = let open Big_int in range ( sub_big_int n m ) ( add_big_int m ( add_big_int n unit_big_int ) )
let two = Big_int . big_int_of_int 2
let big_powers_of_two = let r = range Big_int . zero_big_int ( Big_int . big_int_of_int 66 ) in List . map r ~ f ( : fun x -> Big_int . power_int_positive_big_int 2 x )
let big_interesting_ints = List . map big_powers_of_two ~ f ( : fun x -> big_ints_centered_on two x ) |> List . concat
let best_repr x = try ` Int ( Big_int . int64_of_big_int x ) with nativeint_of_big_int -> ` BigInt x
let interesting_ints = List . map big_interesting_ints ~ f : best_repr
let neg_interesting_ints = List . map ( List . map big_interesting_ints ~ f ( : fun x -> Big_int . minus_big_int x ) ) ~ f : best_repr
let doublify ints = let floats = List . map ints ~ f ( : fun ( ` Int x ) -> ` Float ( Int64 . to_float x ) ) in ` Array floats
let dates = let points = [ - 6106017600000 . 0 ; 0 . 0 ; 946728000000 . 0 ; 1396909037000 . 0 ] in List . map points ~ f ( : fun p -> ` Time ( from_timestamp ( p . / 1000 . 0 ) ) )
let sym_strs = [ " a " ; " ab " ; " abc " ; " abcd " ; " abcde " ; " a1 " ; " b2 " ; " c3 " ; " a_b " ]
let symbols = List . map sym_strs ~ f ( : fun x -> ` Symbol x )
let keywords = List . map sym_strs ~ f ( : fun x -> ` Keyword x )
let one = ` Int ( Int64 . of_int 1 )
let two = ` Int ( Int64 . of_int 2 )
type test_type = JSON | JSON_Verbose | JSON_Write
let read ext t = let fname = String . concat [ " . . / transit - format / examples / 0 . 8 / simple " ; / t ; " . " ; ext ] in In_channel . read_all fname
let skip_string_eq = function | " map_mixed " -> true | " map_nested " -> true | " map_simple " -> true | " map_string_keys " -> true | " maps_three_char_string_keys " -> true | " maps_four_char_sym_keys " -> true | " maps_three_char_sym_keys " -> true | " map_vector_keys " -> true | " set_simple " -> true | " set_nest...
let exemplar ty t expected = let test x = assert_equal ~ printer : Sexp . to_string ( Transit . sexp_of_t expected ) ( Transit . sexp_of_t x ) in match ty with | JSON -> read " json " t |> Transit . from_string |> test | JSON_Verbose -> read " verbose . json " t |> Transit . from_string |> test | JSON_Write -> let stri...
let t ty n expected = n >:: ( fun ( _ ) -> exemplar ty n expected )
let cachecode_tests = let tester expected i = ( fun ( _ ) -> assert_equal ~ printer : String . to_string expected ( Transit . CacheCode . of_int i ) ) in [ " First " >:: ( tester " ^ 0 " 0 ) ; " Second " >:: ( tester " ^ 1 " 1 ) ; " Ninth " >:: ( tester " ^ 9 " 9 ) ; " Break " >:: ( tester " [ " ^ 43 ) ; " After Break ...
let example_tests = [ " dummy " >:: ( fun ( _ ) -> assert_equal ~ printer : Sexp . to_string ( String . sexp_of_t " this " ) ( String . sexp_of_t " this " ) ) ; " string with newline " >:: ( fun ( _ ) -> assert_equal ~ printer : String . to_string " [ " ' " , " \~#\\ a \\ nb " ] " \ ( Transit . to_string ( ` String " a...
let exemplar_tests t = [ t " dates_interesting " ( ` Array dates ) ; t " doubles_interesting " ( ` Array [ fl ( - 3 . 14159 ) ; fl 3 . 14159 ; fl 4E11 ; fl 2 . 998E8 ; fl 6 . 626E - 34 ] ) ; t " doubles_small " ( ints_centered_on 0 |> doublify ) ; t " false " ( ` Bool false ) ; t " ints " ( ` Array ( List . map ( List ...
let exemplar_tests_json = exemplar_tests ( t JSON )
let exemplar_tests_json_verbose = exemplar_tests ( t JSON_Verbose )
let exemplar_tests_json_write = exemplar_tests ( t JSON_Write )
let tests = " Transit " >::: [ " JSON " >::: exemplar_tests_json ; " Example " >::: example_tests ; " CacheCode " >::: cachecode_tests ; " JSON_Verbose " >::: exemplar_tests_json_verbose ; " JSON_Write " >::: exemplar_tests_json_write ; ]
let flatten_result xs : ( int * DB . item * ' trace1 * ' trace2 ) list = concat_map ( fun ( s , itts ) -> map ( fun ( i , t1 , t2 ) -> s , i , t1 , t2 ) itts ) xs
let item ( _ , i , _ , _ : int * DB . item * ' trace1 * ' trace2 ) = i
let alias i = match i . alias with | None -> Path ( i . kind , i . path ) | Some p -> p
let path db = db . path
let path_complexity p = let rec f = function | Oide_ident _ -> 1 | Oide_dot ( p , _ ) -> f p + 1 | Oide_apply ( p1 , p2 ) -> f p1 + f p2 + 3 in f p
let alias_complexity = function | Primitive _ -> 0 | Path ( _ , p ) -> path_complexity p
let package = function | Oide_ident _ -> None | i -> let rec f = function | Oide_ident i -> Some i | Oide_dot ( i , _ ) -> f i | Oide_apply ( i1 , _i2 ) -> f i1 in f i
let package_of_alias = function | Primitive _ -> None | Path ( _ , p ) -> package p
let top_package = function | None -> None | Some p -> match Packpath . parse p with | None -> None | Some [ ] -> assert false | Some ( x :: _ ) -> Some ( top_package_name x )
let ( ) >>> res1 cmp2 = match res1 with | 0 -> cmp2 ( ) | n -> n
let compare_top_packages x y = match x , y with | None , None -> 0 | None , _ -> - 1 | _ , None -> 1 | Some x , Some y when x = y -> 0 | Some " stdlib " , _ -> - 1 | _ , Some " stdlib " -> 1 | Some x , Some y -> compare x y
let group_by_alias ( xs : ( int * DB . item * ' trace1 * ' trace2 ) list ) : ( alias * int * ( int * DB . item * ' trace1 * ' trace2 ) list ) list = let compare_groups ( a1 , d1 , _xs1 ) ( a2 , d2 , _xs2 ) = compare d1 d2 >>> fun ( ) -> compare_top_packages ( top_package & package_of_alias a1 ) ( top_package & package_...
let sort_inside_group items : ( int * DB . item * ' trace1 * ' trace2 ) list list = let nonaliased , aliased = partition ( fun ( _ , i , _ , _ ) -> i . alias = None ) items in let compare_groups g1 g2 = let tp1 = top_package & package & path & item & hd g1 in let tp2 = top_package & package & path & item & hd g2 in com...
let group xs : ( alias * int * ( int * DB . item * ' trace1 * ' trace2 ) list list ) list = map ( fun ( alias , d , xs ) -> ( alias , d , sort_inside_group xs ) ) & group_by_alias & flatten_result xs
let format_alias ppf = function | Path ( k , p ) -> Format . fprintf ppf " % s % a " ( Sig . string_of_k k ) Xoprint . print_ident p | Primitive n -> Format . fprintf ppf " primitive % s " n
let final_print show_v ppf ( g : ( alias * int * ( int * DB . item * ' trace1 * ' trace2 ) list list ) list ) = flip iter g & fun ( a , d , ( xss : ( int * DB . item * ' trace1 * ' trace2 ) list list ) ) -> let nonaliased , aliased = partition ( fun i -> i . alias = None ) & map ( fun ( _ , i , _ , _ ) -> i ) & flatten...
let group_and_print show_v ppf = final_print show_v ppf *< group
module Logfile = struct type t = Sundials_impl . Logfile . t let stderr = Sundials_impl . Logfile . stderr let stdout = Sundials_impl . Logfile . stdout let openfile = Sundials_impl . Logfile . openfile let output_string = Sundials_impl . Logfile . output_string let output_bytes = Sundials_impl . Logfile . output_bytes...
module Profiler = struct type t = Sundials_impl . Profiler . t let enabled = Sundials_configuration . profiling_enabled external make : string -> t = " sunml_profiler_make " external start : t -> string -> unit = " sunml_profiler_begin " [ @@ noalloc ] external finish : t -> string -> unit = " sunml_profiler_end " [ @@...
module Context = struct type t = Sundials_impl . Context . t exception ExternalProfilerInUse = Sundials_impl . Context . ExternalProfilerInUse let make = Sundials_impl . Context . make let default = Sundials_impl . Context . default let get_profiler = Sundials_impl . Context . get_profiler let set_profiler = Sundials_i...
type ' f cfun = ' f Sundials_impl . Callback . cfun
module type ArrayBaseOps = sig type t type elt val error_name : string val create : int -> t val get : t -> int -> elt val set : t -> int -> elt -> unit val length : t -> int