text stringlengths 0 601k |
|---|
module rec Foo : sig type t = private Ojs . t val t_of_js : Ojs . t -> t val t_to_js : t -> Ojs . t val create : string -> t val describe : t -> string val to_bar : t -> Bar . t end = struct type t = Ojs . t let rec t_of_js : Ojs . t -> t = fun ( x2 : Ojs . t ) t -> x2 and t_to_js : t -> Ojs . t = fun ( x1 : Ojs . t ) ... |
module rec A : sig val x : int end = struct let x = B . x end ^^^^^^^^^^^^^^^^^^^^^^ of recursively - defined modules : B -> E -> D -> C -> B . There are no safe modules in this cycle ( see manual section 8 . 2 ) . ^^^^^^^^^^ Module B defines an unsafe value , x . ^^^^^^^^^^ Module E defines an unsafe value , x . ^^^^^... |
module rec A : sig type t += A end = struct type t += A = B . A end |
type t = . . ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ of recursively - defined modules : A -> B -> A . There are no safe modules in this cycle ( see manual section 8 . 2 ) . ^ Module A defines an unsafe extension constructor , A . ^ Module B defines an unsafe extension constructor , A . } ] | |
module rec A : sig module F : functor ( X : sig end ) -> sig end val f : unit -> unit module F ( X : sig end ) = struct end let f ( ) = B . value end of recursively - defined modules : A -> B -> A . There are no safe modules in this cycle ( see manual section 8 . 2 ) . ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Module A d... |
module F ( X : sig module type t module M : t end ) = struct module rec A : sig module M : X . t val f : unit -> unit end = struct module M = X . M let f ( ) = B . value end and B : sig val value : unit end = struct let value = A . f ( ) end end of recursively - defined modules : A -> B -> A . There are no safe modules... |
module rec M : sig val f : unit -> int end = struct let f ( ) = N . x end } ] | |
let check ~ stub txt f = let run mode f = match f mode with | n -> string_of_int n | exception Undefined_recursive_module _ -> " __ " in Printf . printf " % 5s [ % s ] : nonrec => % s , self => % s , mod => % s \ n " %! txt ( if f == stub then " stub " else " real " ) ( run ` Nonrec f ) ( run ` Self f ) ( run ` Mod f ) |
module rec M : sig val f1 : [ ` Nonrec ` | Self ` | Mod ] -> int val f2 : [ ` Nonrec ` | Self ` | Mod ] -> int val f3 : [ ` Nonrec ` | Self ` | Mod ] -> int val f4 : unit -> [ ` Nonrec ` | Self ` | Mod ] -> int val f5 : unit -> [ ` Nonrec ` | Self ` | Mod ] -> int let rec f1 mode = match mode with | ` Nonrec -> 42 | ` ... |
let ( ) = check ~ stub : M . f3 " M . f1 " M . f1 ; check ~ stub : M . f3 " M . f2 " M . f2 ; check ~ stub : M . f3 " M . f3 " M . f3 ; check ~ stub : M . f3 " M . f4 " ( M . f4 ( ) ) ; check ~ stub : M . f3 " M . f5 " ( M . f5 ( ) ) |
module rec Foo : sig class cls : object method go : unit end module M : sig val foo : unit -> cls val bar : cls Lazy . t end class cls = object method go = print_endline " go " end module M = struct let foo ( ) = new Foo . cls let bar = lazy ( foo ( ) ) end end |
let ( ) = List . iter ( fun x -> x # go ) [ new Foo . cls ; Foo . M . foo ( ) ; Lazy . force Foo . M . bar ] |
module Binary_tree : sig type t = | Leaf | Node of t * t [ @@ deriving quickcheck ] type t = | Leaf | Node of t * t [ @@ deriving hash ] let quickcheck_generator = let open Generator . Let_syntax in Generator . recursive_union [ Generator . return Leaf ] ~ f ( : fun self -> [ ( let % map l = self and r = self in Node (... |
module N_ary_tree : sig type ' a t = Node of ' a * ' a t list [ @@ deriving quickcheck ] type ' a t = Node of ' a * ' a t list let quickcheck_generator quickcheck_generator_key = Generator . fixed_point ( fun quickcheck_generator -> [ % quickcheck . generator : key * t list ] |> Generator . map ~ f ( : fun ( key , list... |
let _ = let rec x = 1 :: x in if match x with 1 :: x ' -> x == x ' | _ -> false then print_string " Test 1 : passed \ n " else print_string " Test 1 : FAILED \ n " ; let one = 1 in let rec y = ( one , one + 1 ) :: y in if match y with ( 1 , 2 ) :: y ' -> y == y ' | _ -> false then print_string " Test 2 : passed \ n " e... |
let rec s = " bar " ; ; |
type t = { buffer : Cstruct . buffer ; mutable cons : int ; mutable prod : int ; } |
let capacity t = Bigarray . Array1 . dim t . buffer |
let data_avail t = t . prod - t . cons |
let free_space t = capacity t - t . prod |
let create size = { buffer = Bigarray . ( Array1 . create char c_layout ) size ; cons = 0 ; prod = 0 ; } |
let free_buffer t = if free_space t = 0 && t . cons > 0 then ( let buf = Cstruct . of_bigarray t . buffer in let len = data_avail t in Cstruct . blit buf t . cons buf 0 len ; t . cons <- 0 ; t . prod <- len ; ) ; Cstruct . of_bigarray t . buffer ~ off : t . prod ~ len ( : free_space t ) |
let update_producer t n = assert ( n > 0 ) ; t . prod <- t . prod + n |
let update_consumer t n = let cons = t . cons + n in if cons = t . prod then ( t . cons <- 0 ; t . prod <- 0 ) else ( t . cons <- cons ) |
let data t = Cstruct . of_bigarray t . buffer ~ off : t . cons ~ len ( : data_avail t ) |
let dump f t = let { buffer = _ ; prod ; cons } = t in Fmt . pf f " { prod = % d ; cons = % d } " prod cons |
| Delay | Guard | Return | Dereference ( but not more ) , then it is safe to use [ e ] at the mode [ m ] . used at the modes in [ G ] . ) * |
type sd = Static | Dynamic |
let is_ref : Types . value_description -> bool = function | { Types . val_kind = Types . Val_prim { Primitive . prim_name = " % makemutable " ; prim_arity = 1 } } -> true | _ -> false |
let is_abstracted_arg : arg_label * expression option -> bool = function | ( _ , None ) -> true | ( _ , Some _ ) -> false |
let classify_expression : Typedtree . expression -> sd = let rec classify_expression env e = match e . exp_desc with | Texp_let ( rec_flag , vb , e ) -> let env = classify_value_bindings rec_flag env vb in classify_expression env e | Texp_ident ( path , _ , _ ) -> classify_path env path | Texp_open ( _ , e ) | Texp_let... |
module Mode = struct type t = | Ignore | Delay | Guard | Return | Dereference let equal = ( ( ) = : t -> t -> bool ) let rank = function | Ignore -> 0 | Delay -> 1 | Guard -> 2 | Return -> 3 | Dereference -> 4 let join m m ' = if rank m >= rank m ' then m else m ' let compose m ' m = match m ' , m with | Ignore , _ | _... |
type mode = Mode . t = Ignore | Delay | Guard | Return | Dereference |
module Env : sig type t val single : Ident . t -> Mode . t -> t val empty : t val find : Ident . t -> t -> Mode . t val unguarded : t -> Ident . t list -> Ident . t list val dependent : t -> Ident . t list -> Ident . t list val join : t -> t -> t val join_list : t list -> t val compose : Mode . t -> t -> t val remove :... |
let remove_pat pat env = Env . remove_list ( pat_bound_idents pat ) env |
let remove_patlist pats env = List . fold_right remove_pat pats env |
type term_judg = Mode . t -> Env . t |
type bind_judg = Mode . t -> Env . t -> Env . t |
let option : ' a . ( ' a -> term_judg ) -> ' a option -> term_judg = fun f o m -> match o with | None -> Env . empty | Some v -> f v m |
let list : ' a . ( ' a -> term_judg ) -> ' a list -> term_judg = fun f li m -> List . fold_left ( fun env item -> Env . join env ( f item m ) ) Env . empty li |
let array : ' a . ( ' a -> term_judg ) -> ' a array -> term_judg = fun f ar m -> Array . fold_left ( fun env item -> Env . join env ( f item m ) ) Env . empty ar |
let single : Ident . t -> term_judg = Env . single |
let remove_id : Ident . t -> term_judg -> term_judg = fun id f m -> Env . remove id ( f m ) |
let remove_ids : Ident . t list -> term_judg -> term_judg = fun ids f m -> Env . remove_list ids ( f m ) |
let join : term_judg list -> term_judg = fun li m -> Env . join_list ( List . map ( fun f -> f m ) li ) |
let empty = fun _ -> Env . empty |
let ( ) << : term_judg -> Mode . t -> term_judg = fun f inner_mode -> fun outer_mode -> f ( Mode . compose outer_mode inner_mode ) |
let ( ) >> : bind_judg -> term_judg -> term_judg = fun binder term mode -> binder mode ( term mode ) |
let rec expression : Typedtree . expression -> term_judg = fun exp -> match exp . exp_desc with | Texp_ident ( pth , _ , _ ) -> path pth | Texp_let ( rec_flag , bindings , body ) -> value_bindings rec_flag bindings >> expression body | Texp_letmodule ( x , _ , _ , mexp , e ) -> module_binding ( x , mexp ) >> expression... |
let is_valid_recursive_expression idlist expr = let ty = expression expr Return in match Env . unguarded ty idlist , Env . dependent ty idlist , classify_expression expr with | _ :: _ , _ , _ | [ ] , _ :: _ , Dynamic -> false | [ ] , _ , Static | [ ] , [ ] , Dynamic -> true |
let is_valid_class_expr idlist ce = let rec class_expr : mode -> Typedtree . class_expr -> Env . t = fun mode ce -> match ce . cl_desc with | Tcl_ident ( _ , _ , _ ) -> Env . empty | Tcl_structure _ -> Env . empty | Tcl_fun ( _ , _ , _ , _ , _ ) -> Env . empty | Tcl_apply ( _ , _ ) -> Env . empty | Tcl_let ( rec_flag ,... |
module rec A : sig val even : int -> bool let even n = if n = 0 then true else if n = 1 then false else B . odd ( n - 1 ) 1 val odd : int -> bool let odd n = if n = 1 then true else if n = 0 then false else A . even ( n - 1 ) 1 end |
module rec AA : sig val even : int -> bool val x : unit -> int let even n = if n = 0 then true else if n = 1 then false else BB . odd ( n - 1 ) 1 let x ( ) = BB . y ( ) + 3 val odd : int -> bool val y : unit -> int let odd n = if n = 1 then true else if n = 0 then false else AA . even ( n - 1 ) 1 let y ( ) = 32 end |
module rec Even : sig type t = Zero | Succ of Odd . t type t = Zero | Succ of Odd . t type t = Succ of Even . t type t = Succ of Even . t |
module rec AAA : sig type t = Leaf of string | Node of ASet . t val compare : t -> t -> int end type t = Leaf of string | Node of ASet . t let compare t1 t2 = match ( t1 , t2 ) t2 with ( Leaf s1 , Leaf s2 ) s2 -> Pervasives . compare s1 s2 | ( Leaf _ , Node _ ) _ -> 1 | ( Node _ , Leaf _ ) _ -> - 1 | ( Node n1 , Node n... |
let suites = Mt [ . " test1 " , ( fun _ -> Eq ( ( true , true , false , false ) false , ( A . even 2 , AA . even 4 , B . odd 2 , BB . odd 4 ) ) ) ; " test2 " , ( fun _ -> Eq ( Eq ( BB . y ( ) , 32 ) 32 ) 32 ) 32 ; " test3 " , ( fun _ -> Eq ( EqAA . x ( ) , 35 ) 35 ) 35 ; " test4 " , ( fun _ -> Eq ( true , A . even 2 ) ... |
module Scheduler = Sched_ws . Make ( struct let num_domains = 4 let is_affine = false end ) |
let flip f a b = f b a |
let rec lock_and_call l i = flip run ( ) @@ RLock . acq l ; callback l i ; ignore ( flip run ( ) @@ RLock . rel l ) |
let main ( ) = let l = RLock . create ( ) in fork_on ( fun ( ) -> run ( RLock . acq l ) ( ) ; lock_and_call l 1 ; ignore ( run ( RLock . rel l ) ( ) ) ) 2 ; let cdl = CDL . create ( 100 + ( 100 * 2 ) ) in for i = 0 to 99 do fork_on ( fun ( ) -> lock_and_call l 100 ; run ( CDL . count_down cdl ) ( ) ) ( i mod 4 ) done ;... |
let ( ) = Scheduler . run main |
let rec x = 1 :: x |
let rec a = 2 :: b |
let rec xx = let v = 1 in v :: xx |
let rec naive = let uu = naive in function | 0 | 1 -> 1 | n -> n + uu ( n - 1 ) 1 + uu ( n - 2 ) 2 |
let rec fib = let one = 1 in let four = ref 2 in let three = ref 3 in let u = fib in let h = lazy fib in let v = ref ( fun _ -> assert false ) false in function | 0 -> ! four | 1 -> one | 2 -> ! three | 3 -> v := Lazy . force h ; one | n -> fib ( n - 1 ) 1 + u ( n - 2 ) 2 |
let rec xs = let rec ys = 1 :: ys and _zs ( ) = ( List . hd ys , List . hd ( fst xs ) xs ) xs in ( 2 :: List . hd ys :: [ ] , _zs ) _zs |
let rec xs = let zs ( ) = ( List . hd ( fst xs ) xs ) xs in ( 2 :: [ ] , zs ) zs |
let rec fib2 = let _one = ( fun _ -> 1 + two ) two in function | 0 | 1 -> 1 | n -> fib2 ( n - 1 ) 1 + fib2 ( n - 2 ) 2 |
let rec fib3 = let _one = ( fun _ -> 1 + two ) two in function | 0 | 1 -> 1 | n -> fib3 ( n - 1 ) 1 + fib3 ( n - 2 ) 2 |
let rec even = let odd n = if n == 1 then true else even ( n - 1 ) 1 in fun n -> if n == 0 then true else odd ( n - 1 ) 1 |
let rec even2 = let odd = even2 in fun n -> if n == 0 then true else odd ( n - 1 ) 1 |
let rec lazy_v = lazy ( fun _ -> ignore @@ Lazy . force lazy_v ) lazy_v |
let rec sum = let a = sum in fun acc n -> if n > 0 then a ( acc + n ) n ( n - 1 ) 1 else acc |
let rec fake_v = 1 :: 2 [ ] :: |
let rec fake_y = 2 :: 3 [ ] :: |
let rec fake_z2 = 1 ( :: sum 0 10 ) 10 :: fake_y2 |
let rec v = 3 |
type u = | B of string * ( unit -> u ) u | A of int * ( unit -> u ) u |
let rec rec_variant_b = B ( " gho " , ( fun _ -> rec_variant_a ) rec_variant_a ) rec_variant_a A ( 3 , fun _ -> rec_variant_b ) rec_variant_b |
let suites = Mt [ . " hd " , ( fun _ -> Eq ( Eq1 , List . hd ( List . tl x ) x ) x ) x ; " mutual " , ( fun _ -> Eq ( 3 , ( match a with | _ :: _ :: _ :: _ :: c :: _ -> c | _ -> assert false ) ) ) ; " rec_sum " , ( fun _ -> Eq ( Eq55 , sum 0 10 ) 10 ) 10 ; __LOC__ , ( fun _ -> Eq ( Eq [ Eq1 ; 2 ] 2 , fake_v ) fake_v ) ... |
let rec Js . log n ; n + 1 |
let rec n + 1 |
let fake_inline_inlie2 = fake_inline_minus 3 ; ; Mt . from_pair_suites __FILE__ suites |
let fwd_v2 target = ( target , " https :// v2 . ocaml . org " ^ target ) target |
let v2_assets = [ fwd_v2 " / meetings / ocaml / 2013 / proposals / core - bench . pdf " ; fwd_v2 " / meetings / ocaml / 2013 / proposals / ctypes . pdf " ; fwd_v2 " / meetings / ocaml / 2013 / proposals / formats - as - gadts . pdf " ; fwd_v2 " / meetings / ocaml / 2013 / proposals / frenetic . pdf " ; fwd_v2 " / meeti... |
let from_v2 = [ ( " / about . fr . html " , Url . about ) about ; ( " / about . html " , Url . about ) about ; ( " / caml - light / faq . html " , Url . index ) index ; ( " / caml - light / index . html " , Url . index ) index ; ( " / caml - light " , / Url . index ) index ; ( " / caml - light / license . html " , Url ... |
let redirect_p pattern = let handler req = let target = Dream . target req in Dream . redirect req ( " https :// v2 . ocaml . org " ^ target ) target in Dream . get pattern handler |
let fwd_v2 origin = Dream . get origin ( fun req -> Dream . redirect req ( " https :// v2 . ocaml . org " ^ origin ) origin ) origin |
let manual = [ redirect_p " / api " ; /** fwd_v2 " / api " ; / redirect_p " / manual " ; /** fwd_v2 " / manual " ; / redirect_p " / releases / 3 . 12 / htmlman " ; /** fwd_v2 " / releases / 3 . 12 / htmlman " ; / redirect_p " / releases / 4 . 00 / htmlman " ; /** fwd_v2 " / releases / 4 . 00 / htmlman " ; / redirect_p ... |
let make ( ? permanant = false ) false t = let status = if permanant then ` Moved_Permanently else ` See_Other in Dream . scope " " [ Dream_encoding . compress ] ( List . filter_map ( fun ( origin , new_ ) new_ -> if origin = new_ then None else Some ( Dream . get origin ( fun req -> Dream . redirect ~ status req new_ ... |
let t = Dream . scope " " [ ] [ make from_v2 ; make v2_assets ; Dream . scope " " [ Dream_encoding . compress ] manual ; ] |
let cat file = let fd = Unix . openfile file [ Unix . O_RDONLY ] 0 in let buf = Bytes . create 1024 in let rec cat ( ) = let n = Unix . read fd buf 0 ( Bytes . length buf ) in if n > 0 then ( ignore ( Unix . write Unix . stdout buf 0 n ) ; cat ( ) ) in cat ( ) ; Unix . close fd |
let out fd txt = ignore ( Unix . write_substring fd txt 0 ( String . length txt ) ) |
let refl = Filename . concat Filename . current_dir_name " reflector . exe " |
let test_createprocess systemenv = let f_out = Unix . ( openfile " . / tmpout . txt " [ O_WRONLY ; O_TRUNC ; O_CREAT ; O_CLOEXEC ] 0o600 ) in let f_err = Unix . ( openfile " . / tmperr . txt " [ O_WRONLY ; O_TRUNC ; O_CREAT ; O_CLOEXEC ] 0o600 ) in let ( p_exit , p_entrance ) = Unix . pipe ~ cloexec : true ( ) in let p... |
let test_2ampsup1 ( ) = let pid = Unix . create_process refl [ | refl ; " - o " ; " 123 " ; " - e " ; " 456 " ; " - o " ; " 789 " ] | Unix . stdin Unix . stdout Unix . stdout in let ( _ , status ) = Unix . waitpid [ ] pid in if status <> Unix . WEXITED 0 then out Unix . stdout " !!! reflector exited with an error \ n " |
let test_swap12 ( ) = let pid = Unix . create_process refl [ | refl ; " - e " ; " 123 " ] | Unix . stdin Unix . stderr Unix . stdout in let ( _ , status ) = Unix . waitpid [ ] pid in if status <> Unix . WEXITED 0 then out Unix . stdout " !!! reflector exited with an error \ n " |
let test_open_process_in ( ) = let ic = Unix . open_process_in ( refl ^ " - o 123 - o 456 " ) in out Unix . stdout ( input_line ic ^ " \ n " ) ; out Unix . stdout ( input_line ic ^ " \ n " ) ; let status = Unix . close_process_in ic in if status <> Unix . WEXITED 0 then out Unix . stdout " !!! reflector exited with an ... |
let test_open_process_out ( ) = let oc = Unix . open_process_out ( refl ^ " - i2o - i2o - i2o " ) in output_string oc " aa \ nbbbb \ n " ; close_out oc ; let status = Unix . close_process_out oc in if status <> Unix . WEXITED 0 then out Unix . stdout " !!! reflector exited with an error \ n " |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.