text stringlengths 12 786k |
|---|
module M : sig val f : [ < ` A & ' a = int * float | ` B & ' a = bool * string ] -> ' a |
let f = multifun ` A ` | B as x -> f x ; ; |
let f = multifun ` A -> ( multifun ` C -> 1 | ` D -> 1 . ) | ` B -> ( multifun ` C -> true | ` D -> " 1 " ) ; ; |
module M : sig val f : [ < ` A & ' b = [ < ` C & ' a = int | ` D & ' a = float & ' c = bool ] -> ' a | ` B & ' b = [ < ` C & ' c = bool | ` D & ' c = string ] -> ' c ] -> ' b |
module M : sig val f : [ < ` A & ' b = [ < ` C & ' a = int | ` D & ' a = bool ] -> ' a | ` B & ' b = [ < ` C & ' c = bool | ` D & ' c = string ] -> ' c ] -> ' b |
module M : sig val f : [ < ` A & ' b = [ < ` C & ' a = int | ` D ] -> ' a | ` B & ' b = [ < ` C & ' c = bool | ` D & ' c = string ] -> ' c ] -> ' b |
let r = ref [ ] |
let f = multifun ` A -> 1 | ` B -> true |
let g x = r := [ f x ] ; ; |
module M : sig val g : [ < ` A & ' a = int | ` B & ' a = bool ] -> unit |
let r = ref [ ] |
let f = multifun ` A -> r | ` B -> ref [ ] ; ; |
module M : sig val f : [ < ` A & ' b = int list ref | ` B & ' b = ' c list ref ] -> ' b |
let l : int list ref = r ; ; |
module M : sig val f : [ < ` A & ' b = int list ref | ` B & ' b = ' c list ref ] -> ' b |
let f = multifun ` A -> ( 1 , [ ] ) | ` B -> ( true , [ ] ) |
let g x = fst ( f x ) ; ; |
module M : sig val g : [ < ` A & ' a * ' b = int * bool | ` B & ' a * ' b = bool * int ] -> ' a |
let g = multifun ( ` A ` | B ) as x -> g x ; ; |
let f x = let a = multimatch x with ` A -> 1 | ` B -> " 1 " in ( multifun ` A -> print_int | ` B -> print_string ) x a ; ; |
let f = multifun ( ` A ` | B ) as x -> f x ; ; |
type unit_op = [ ` Set of int | ` Move of int ] |
let op r = multifun ` Get -> ! r | ` Set x -> r := x | ` Move dx -> r := ! r + dx ; ; |
let rec trace r = function [ ] -> [ ] | op1 :: ops -> multimatch op1 with # int_op as op1 -> let x = op r op1 in x :: trace r ops | # unit_op as op1 -> op r op1 ; trace r ops ; ; val mutable x : int = x method get = x method set y = x <- y method move dx = x <- x + dx end ; ; |
let poly sort coeffs x = let add , mul , zero = multimatch sort with ` Int -> ( ) , + ( * ) , 0 | ` Float -> ( . ) , + ( . * ) , 0 . in let rec compute = function [ ] -> zero | c :: cs -> add c ( mul x ( compute cs ) ) in compute coeffs ; ; |
module M : sig val poly : [ < ` Int & ' a = int | ` Float & ' a = float ] -> ' a list -> ' a -> ' a |
type ( ' a , ' b ) num_sort = ' b constraint ' b = [ < ` Int & ' a = int | ` Float & ' a = float ] |
module M : sig val poly : ( ' a , _ ) num_sort -> ' a list -> ' a -> ' a |
type num = [ ` Int | ` Float ] |
let print0 = multifun ` Int -> print_int | ` Float -> print_float ; ; |
let print1 = multifun # num as x -> print0 x | ` List t -> List . iter ( print0 t ) | ` Pair ( t1 , t2 ) -> ( fun ( x , y ) -> print0 t1 x ; print0 t2 y ) ; ; |
module Make ( Bits : sig val multiply_by : int val bits : int end ) = struct open Hardcaml . Signal module I = struct type ' a t = { input : ' a [ @ bits Bits . bits ] } [ @@ deriving sexp_of , hardcaml ] end module O = struct let num_bits = Bits . bits + Int . ceil_log2 Bits .... |
let command = Async . Command . async ~ summary " : multiply by constant logic " ( let open Command . Let_syntax in let % map_open ( ) = return ( ) and flags = Hardcaml_xilinx_reports . Command . Command_flags . flags and bits = flag " bits " ( required int ) ~ doc " : BITS ... |
type ' a reporter = ' a -> unit |
module type S = sig type ' a line type ' a reporter type ( ' a , ' b ) t ( float reporter -> ' b , ' b ) t ( int64 reporter -> ( string * float ) reporter -> ' b , ' b ) t ] } These reporting functions are supplied when beginning the { { ! rendering } rendering } ... |
module Hlist ( Elt : sig type ' a t struct type ( _ , _ ) t = | Zero : ( ' a , ' a ) t | One : ' a Elt . t -> ( ' a reporter -> ' b , ' b ) t | Many : ' a Elt . t list -> ( ' a reporter list -> ' b , ' b ) t | Plus : ( ( ' a , ' b ) t * ( ... |
module type Multi = sig module type S = S module Hlist = Hlist include S with type ' a line := ' a Line . t and type ' a reporter := ' a -> unit and type ( ' a , ' b ) t = ( ' a , ' b ) Hlist ( Line ) . t end |
type t = | Mutable | Immutable | Immutable_unique |
let [ @ ocamlformat " disable " ] print ppf t = match t with | Mutable -> Format . pp_print_string ppf " Mutable " | Immutable -> Format . pp_print_string ppf " Immutable " | Immutable_unique -> Format . pp_print_string ppf " Immutable_unique " |
let compare t1 t2 = match t1 , t2 with | Mutable , Mutable | Immutable , Immutable | Immutable_unique , Immutable_unique -> 0 | Mutable , ( Immutable | Immutable_unique ) -> - 1 | Immutable , Immutable_unique -> - 1 | Immutable , Mutable -> 1 | Immutable_unique , ( Mutable | Im... |
let join t1 t2 = match t1 , t2 with | Immutable , Immutable -> Immutable | Immutable_unique , Immutable_unique | Immutable , Immutable_unique | Immutable_unique , Immutable -> Immutable_unique | Mutable , ( Mutable | Immutable | Immutable_unique ) | ( Immutable | Immutable_unique ) , M... |
let to_lambda t : Asttypes . mutable_flag = match t with | Mutable -> Mutable | Immutable -> Immutable | Immutable_unique -> Immutable |
let from_lambda ( flag : Lambda . mutable_flag ) : t = match flag with | Mutable -> Mutable | Immutable -> Immutable | Immutable_unique -> Immutable_unique |
let is_mutable t = match t with Mutable -> true | Immutable | Immutable_unique -> false |
module type RPC = sig type transport type id type request_hdr type request_body type response_hdr type response_body val recv_hdr : transport -> ( id option * response_hdr ) Lwt . t val recv_body : transport -> request_hdr -> response_hdr -> response_body -> ( unit , Protocol . Error . t ) resu... |
module Make ( R : RPC ) : sig type client val rpc : R . request_hdr -> R . request_body -> R . response_body -> client -> ( unit , Protocol . Error . t ) Result . result Lwt . t val create : R . transport -> client Lwt . t exception Unexpected_id of R . id exception Shutdown type ... |
module TestPacket = struct type id = int type request_hdr = { req_id : int ; req_payload : bytes } [ @@ deriving sexp ] type request_body = bytes type response_hdr = { res_id : int option ; res_payload : bytes } [ @@ deriving sexp ] type response_body = bytes type seq = Request of reque... |
module T = Nbd . Mux . Make ( TestPacket ) |
let p1 = TestPacket . { req_id = 1 ; req_payload = " p1 " |> Bytes . of_string } |
let p2 = TestPacket . { req_id = 2 ; req_payload = " p2 " |> Bytes . of_string } |
let r1 = TestPacket . { res_id = Some 1 ; res_payload = " r1 " |> Bytes . of_string } |
let r2 = TestPacket . { res_id = Some 2 ; res_payload = " r2 " |> Bytes . of_string } |
let ( >>|= ) m f = m >>= function | Ok x -> f x | Error x -> Lwt . fail_with ( Nbd . Protocol . Error . to_string x ) |
let test_rpc = ( " Basic test of the rpc function " , ` Quick , fun ( ) -> let t = let transport = TestPacket . create ( ) in T . create transport >>= fun client -> let open TestPacket in let response = Bytes . create 2 in let t1 = T . rpc p1 p1 . req_payload response client in Te... |
let test_multi_rpc = ( " Test queuing of rpc calls in the mux " , ` Quick , fun ( ) -> let t = let transport = TestPacket . create ( ) in T . create transport >>= fun client -> let open TestPacket in let response1 = Bytes . create 2 in let response2 = Bytes . create 2 in let t1 = ... |
let test_out_of_order_responses = ( " Test RPC functions work when responses are received out of order " , ` Quick , fun ( ) -> let t = let transport = TestPacket . create ( ) in T . create transport >>= fun client -> let open TestPacket in let response1 = Bytes . create 2 in let respo... |
let test_memory_leak = ( " Check the mux does not have a memory leak " , ` Quick , fun ( ) -> let t = let transport = TestPacket . create ( ) in T . create transport >>= fun client -> let open TestPacket in let response1 = Bytes . create 2 in TestPacket . record_sequence := false ; ... |
let test_exception_handling = ( " Check that exceptions raised are handled correctly " , ` Quick , fun ( ) -> let t = let transport = TestPacket . create ( ) in T . create transport >>= fun client -> let open TestPacket in let response1 = Bytes . create 2 in TestPacket . queue_respon... |
let tests = ( " Mux tests " , [ test_rpc ; test_multi_rpc ; test_out_of_order_responses ; test_memory_leak ; test_exception_handling ] ) |
let ( ) = Alcotest . run " Sync Nbd library test suite " [ tests ] |
let split s ch = let x = ref [ ] in let rec go s = let pos = String . index s ch in x := ( String . before s pos ) ::! x ; go ( String . after s ( pos + 1 ) ) in try go s with Not_found -> ! x |
let split_nl s = split s ' \ n ' |
let before_space s = try String . before s ( String . index s ' ' ) with Not_found -> s |
let find_packages ( ) = List . map before_space ( split_nl & run_and_read " ocamlfind list " ) |
let find_syntaxes ( ) = [ " camlp4o " ; " camlp4r " ] |
let ocamlfind x = S [ A " ocamlfind " ; x ] |
let camlidl = S ( [ A " camlidl " ; A " - header " ] ) |
let getline_from_cmd cmd = let ch = Unix . open_process_in cmd in let line = input_line ch in ignore ( Unix . close_process_in ch ) ; line |
let ocamlpath = getline_from_cmd " ocamlfind printconf path " |
let camlidlpath = getline_from_cmd " ocamlfind query camlidl " |
let get_os_type ( ) = getline_from_cmd " uname " |
let _ = dispatch begin function | Before_options -> Options . ocamlc := ocamlfind & A " ocamlc " ; Options . ocamlopt := ocamlfind & A " ocamlopt " ; Options . ocamldep := ocamlfind & A " ocamldep " ; Options . ocamldoc := ocamlfind & A " ocamldoc " ; Options . ocamlmktop ... |
module StrMap = Map . Make ( struct type t = string let compare = compare end ) |
let _ = Callback . register_exception " mysql error " ( Error " Registering Callback " ) |
let fail msg = raise ( Failure msg ) |
type error_code = Aborting_connection | Access_denied_error | Alter_info | Bad_db_error | Bad_field_error | Bad_host_error | Bad_null_error | Bad_table_error | Blob_cant_have_default | Blob_key_without_length | Blob_used_as_key | Blobs_and_no_terminated | Cant_create_db | Cant_create_file | Cant_create_t... |
let error_of_int code = match code with |
let pretty_type = function | IntTy -> " integer " | FloatTy -> " float " | StringTy -> " string " | SetTy -> " set " | EnumTy -> " enum " | DateTimeTy -> " datetime " | DateTy -> " date " | TimeTy -> " time " | YearTy -> " year " | TimeStampTy -> " timestamp " ... |
type db = { dbhost : string option ; dbname : string option ; dbport : int option ; dbpwd : string option ; dbuser : string option ; dbsocket : string option } |
type field = { name : string ; table : string option ; def : string option ; ty : dbty ; max_length : int ; flags : int ; decimals : int } |
let defaults = { dbhost = None ; dbname = None ; dbport = None ; dbpwd = None ; dbuser = None ; dbsocket = None ; } |
let connect ( ? options [ ] ) = db = connect options db |
let quick_connect ? options ? host ? database ? port ? password ? user ? socket ( ) = connect ? options { dbhost = host ; dbname = database ; dbport = port ; dbpwd = password ; dbuser = user ; dbsocket = socket ; } |
let quick_change ? user ? password ? database conn = change_user conn { defaults with dbuser = user ; dbpwd = password ; dbname = database } |
let escape s = init ( ) ; db_escape s |
let status dbd = let x = real_status dbd in match x with | 0 -> StatusOK | 1065 -> StatusEmpty | _ -> StatusError ( error_of_int x ) |
let errno dbd = error_of_int ( real_status dbd ) |
let sub start len str = int_of_string ( String . sub str ~ pos : start ~ len ) |
let int2ml str = int_of_string str |
let decimal2ml str = str |
let int322ml str = Int32 . of_string str |
let int642ml str = Int64 . of_string str |
let nativeint2ml str = Nativeint . of_string str |
let float2ml str = float_of_string str |
let str2ml str = str |
let enum2ml str = str |
let blob2ml str = str |
let set2ml str = let rec wsp acc i = if i = String . length str then acc else match str . [ i ] with | ' ' | ' \ t ' | ' \ n ' | ' \ r ' | ' , ' -> wsp acc ( i + 1 ) | _ -> loop acc i ( i + 1 ) and loop acc p_start i = if i = String . length str then ( Stri... |
let datetime2ml str = assert ( String . length str = 19 ) ; let year = sub 0 4 str in let month = sub 5 2 str in let day = sub 8 2 str in let hour = sub 11 2 str in let minute = sub 14 2 str in let second = sub 17 2 str in ( year , month , day , hour , minute , second ) |
let date2ml str = assert ( String . length str = 10 ) ; let year = sub 0 4 str in let month = sub 5 2 str in let day = sub 8 2 str in ( year , month , day ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.