text stringlengths 12 786k |
|---|
let make_runtime_error ? request_id ~ recoverable msg = RuntimeError { msg ; request_id ; recoverable } |
let make_api_error ? request_id ~ recoverable msg = ApiError { msg ; request_id ; recoverable } |
let make_handler_error msg = HandlerError { error_message = msg ; error_type = Constants . error_type_handled } |
let is_recoverable = function | ApiError { recoverable ; _ } | RuntimeError { recoverable ; _ } -> recoverable |
let message : type a . a t -> string = function | HandlerError { error_message ; _ } -> error_message | ApiError { msg ; _ } -> msg | RuntimeError { msg ; _ } -> msg |
let request_id = function | ApiError { request_id ; _ } -> request_id | RuntimeError { request_id ; _ } -> request_id |
let to_lambda_error : type a . ? handled : bool -> a t -> Yojson . Safe . t = fun ( ? handled = true ) error -> let make_lambda_error e = { error_message = e . msg ; error_type = ( if handled then Constants . error_type_handled else Constants . error_type_unhandled ) } in let lambd... |
let rec apply func args = let params_len = L . length func . params in let args_len = L . length args in let env = ( match func . vararg with | None -> if params_len == args_len then Env . bind_locals func . closure ( List . combine func . params args ) else arg_count_mismatch ( string_of... |
type bigstring = ( char , int8_unsigned_elt , c_layout ) Array1 . t bigstring -> int -> int = " % caml_bigstring_get16 " bigstring -> int -> int -> unit = " % caml_bigstring_set16 " |
let bigstring_of_string s = let a = Array1 . create char c_layout ( String . length s ) in for i = 0 to String . length s - 1 do a . { i } <- s . [ i ] done ; a |
let ( ) = String . get ( print_endline " hello " ; " foo " ) ( print_endline " world " ; 0 ) |> Printf . printf " % c \ n " ; caml_bytes_get_16 ( print_endline " hello " ; Bytes . make 10 ' \ x00 ' ) ( print_endline " world " ; 0 ) |> Printf . p... |
type ' a basic_event = { poll : unit -> bool ; suspend : unit -> unit ; result : unit -> ' a } |
type ' a behavior = int ref -> Condition . t -> int -> ' a basic_event |
type ' a event = Communication of ' a behavior | Choose of ' a event list | WrapAbort of ' a event * ( unit -> unit ) | Guard of ( unit -> ' a event ) |
type ' a channel = { mutable writes_pending : ' a communication Queue . t ; mutable reads_pending : ' a communication Queue . t } { performed : int ref ; condition : Condition . t ; mutable data : ' a option ; event_number : int } |
let new_channel ( ) = { writes_pending = Queue . create ( ) ; reads_pending = Queue . create ( ) } |
let do_aborts abort_env genev performed = if abort_env <> [ ] then begin if performed >= 0 then begin let ids_done = snd genev . ( performed ) in List . iter ( fun ( id , f ) -> if not ( List . mem id ids_done ) then f ( ) ) abort_env end else begin List . iter ( fun ( _ , ... |
let basic_sync abort_env genev = let performed = ref ( - 1 ) in let condition = Condition . create ( ) in let bev = Array . make ( Array . length genev ) ( fst ( genev . ( 0 ) ) performed condition 0 ) in for i = 1 to Array . length genev - 1 do bev . ( i ) <- ( fs... |
let scramble_array a = let len = Array . length a in if len = 0 then invalid_arg " Event . choose " ; for i = len - 1 downto 1 do let j = Random . int ( i + 1 ) in let temp = a . ( i ) in a . ( i ) <- a . ( j ) ; a . ( j ) <- temp done ; a |
let gensym = let count = ref 0 in fun ( ) -> incr count ; ! count |
let rec flatten_event ( abort_list : int list ) ( accu : ( ' a behavior * int list ) list ) ( accu_abort : ( int * ( unit -> unit ) ) list ) ev = match ev with Communication bev -> ( ( bev , abort_list ) :: accu ) , accu_abort | WrapAbort ( ev , fn ) -> let id = g... |
let sync ev = let ( evl , abort_env ) = flatten_event [ ] [ ] [ ] ev in basic_sync abort_env ( scramble_array ( Array . of_list evl ) ) |
let basic_poll abort_env genev = let performed = ref ( - 1 ) in let condition = Condition . create ( ) in let bev = Array . make ( Array . length genev ) ( fst genev . ( 0 ) performed condition 0 ) in for i = 1 to Array . length genev - 1 do bev . ( i ) <- fst genev . ... |
let poll ev = let ( evl , abort_env ) = flatten_event [ ] [ ] [ ] ev in basic_poll abort_env ( scramble_array ( Array . of_list evl ) ) |
let cleanup_queue q = let q ' = Queue . create ( ) in Queue . iter ( fun c -> if ( ! c . performed ) = - 1 then Queue . add c q ' ) q ; q ' |
let always data = Communication ( fun performed condition evnum -> { poll = ( fun ( ) -> performed := evnum ; true ) ; suspend = ( fun ( ) -> ( ) ) ; result = ( fun ( ) -> data ) } ) |
let send channel data = Communication ( fun performed condition evnum -> let wcomm = { performed = performed ; condition = condition ; data = Some data ; event_number = evnum } in { poll = ( fun ( ) -> let rec poll ( ) = let rcomm = Queue . take channel . reads_pending in if ( ... |
let receive channel = Communication ( fun performed condition evnum -> let rcomm = { performed = performed ; condition = condition ; data = None ; event_number = evnum } in { poll = ( fun ( ) -> let rec poll ( ) = let wcomm = Queue . take channel . writes_pending in if ( ! wcom... |
let choose evl = Choose evl |
let wrap_abort ev fn = WrapAbort ( ev , fn ) |
let guard fn = Guard fn |
let rec wrap ev fn = match ev with Communication genev -> Communication ( fun performed condition evnum -> let bev = genev performed condition evnum in { poll = bev . poll ; suspend = bev . suspend ; result = ( fun ( ) -> fn ( bev . result ( ) ) ) } ) | Choose evl -> Choose (... |
let select evl = sync ( Choose evl ) |
type code_event = { ev_frag : int ; ev_ev : Instruct . debug_event } |
let get_pos ev = match ev . ev_kind with | Event_before -> ev . ev_loc . Location . loc_start | Event_after _ -> ev . ev_loc . Location . loc_end | _ -> ev . ev_loc . Location . loc_start ; ; |
let current_event = ref ( None : code_event option ) |
let get_current_event ( ) = match ! current_event with | None -> raise Not_found | Some ev -> ev |
let current_event_is_before ( ) = match ! current_event with None -> raise Not_found | Some { ev_ev = { ev_kind = Event_before } } -> true | _ -> false |
let intent_help = Wcs . intent " help " ~ description " : The user needs help knowing what to do " ~ examples [ : " help " ; " I am confused " ; " What can I do " ; " What are my choices " ; " options " ; " alternatives " ; " choices " ; " usage " ; " g... |
let is_number = Wcs . dialog_node " Is number " ~ conditions_spel : ( Spel . entity Wcs . sys_number ( ) ) ~ text : " You have selected the number @ sys - number . " ~ context : ( Context . skip_user_input true ) ( ) |
let win = Wcs . dialog_node " Win " ~ parent : is_number ~ conditions : " @ sys - number == 42 " ~ text : " You win " ! ~ context : ( Context . return ( Json . bool true ) ) ( ) |
let lost = Wcs . dialog_node " Lost " ~ previous_sibling : win ~ conditions : " anything_else " ~ text : " Sorry , do you want to try again " ? ( ) |
let mk_prompt prompt_txt help_txt = let prompt = Wcs . dialog_node " Prompt " ~ conditions : " conversation_start " ~ text : prompt_txt ( ) in let help = Wcs . dialog_node " Help " ~ conditions : " # help " ~ text : help_txt ~ next_step : ( prompt , Goto_body ) ( ) in let... |
let example1 = Wcs . workspace " Example 1 " ~ intents : [ intent_help ] ~ entities : [ Wcs . sys_number ] ~ dialog_nodes : ( is_number :: win :: lost :: ( mk_prompt " Enter a number . " " It is a game where you have to guest a number . " ) ) ( ) |
let main ( ) = let wcs_cred_file = ref None in let ws_id = ref None in let print = ref false in let deploy = ref false in let exec = ref false in let speclist = Arg . align [ " - cred " , Arg . String ( fun s -> wcs_cred_file := Some s ) , " cred . json The file containing the Watson... |
let _ = begin try main ( ) with | Log . Error ( module_name , msg ) when not ! Log . debug_message -> Format . eprintf " % s . " @ msg ; exit 1 end |
let parse_version : string -> ( int * int * int * string option ) option = let parse_opt_v s = match String . Sub . head s with | Some ( ' v ' ' | V ' ) -> String . Sub . tail s | Some _ -> s | None -> raise Exit in let parse_dot s = match String . Sub . head s with | Some '... |
let parse_env : string -> string String . map option = let skip_white s = String . Sub . drop ~ sat : Char . Ascii . is_white s in let parse_key s = let id_char c = Char . Ascii . is_letter c || c = ' _ ' in match String . Sub . span ~ min : 1 ~ sat : id_char s with | ( key , ... |
let show exn = let error fmt = eprintf ( " % serror % s : " ^^ fmt ) ( color_white ( ) ) ( color_white ( ) ) in match exn with | Arg . Bad err -> eprintf " % s \ n " err ; exit 2 | Arg . Help h -> eprintf " % s \ n " h ; exit 0 | Project . NoConfFile -> error ... |
let interrupted = ref false |
let is_protected = ref false |
let break _signum = if ! is_protected then interrupted := true else raise Sys . Break |
let _ = match Sys . os_type with " Win32 " -> ( ) | _ -> Sys . set_signal Sys . sigint ( Sys . Signal_handle break ) ; Sys . set_signal Sys . sigpipe ( Sys . Signal_handle ( fun _ -> raise End_of_file ) ) |
let protect f = if ! is_protected then f ( ) else begin is_protected := true ; if not ! interrupted then f ( ) ; is_protected := false ; if ! interrupted then begin interrupted := false ; raise Sys . Break end end |
let unprotect f = if not ! is_protected then f ( ) else begin is_protected := false ; if ! interrupted then begin interrupted := false ; raise Sys . Break end ; f ( ) ; is_protected := true end |
val mutable x = x_init method get_x = x method move d = x <- x + d end ; ; |
let p = new point 7 ; ; p # get_x ; ; p # get_x ; ; |
let q = Oo . copy p ; ; inherit point x val c = c method color = c end ; ; |
let p ' = new color_point 5 " red " ; ; |
let l = [ p ; ( p ' :> point ) ] ; ; |
let get_x p = p # get_x ; ; |
let set_x p = p # set_x ; ; val mutable x = x_init method get = x method set y = x <- y end ; ; val mutable x = x_init method get = x method set y = x <- y end ; ; val mutable x = ( x_init : ' a ) method get = x method set y = x <- y end ; ; |
let r = new ref 1 in r # set 2 ; ( r # get ) ; ; val mutable center = c method center = center method set_center c = center <- c method move = ( center # move : int -> unit ) end ; ; constraint ' a = # point val mutable center = c method center = center method set_center c = center... |
let ( c , c ' ) = ( new circle p , new circle p ' ) ; ; constraint ' a = # color_point inherit [ ' a ] circle c method color = center # color end ; ; |
let c ' ' = new color_circle p ; ; |
let c ' ' = new color_circle p ' ; ; inherit point y method print = print_int s # get_x end ; ; |
let p = new printable_point 7 ; ; p # print ; ; inherit color_point y c inherit printable_point y as super method print = print_string " ( " ; super # print ; print_string " , " ; print_string ( self # color ) ; print_string " ) " end ; ; |
let p ' = new printable_color_point 7 " red " ; ; p ' # print ; ; val x = y method get_x = x method move d = { < x = x + d } > end ; ; |
let p = new functional_point 7 ; ; p # get_x ; ; p # get_x ; ; method virtual null : bool method virtual hd : ' a method virtual tl : ' a lst method map f = ( if self # null then new nil ( ) else new cons ( f self # hd ) ( self # tl # map f ) : ' a lst ) method iter ( f ... |
let l1 = new cons 3 ( new cons 10 ( new nil ( ) ) ) ; ; |
let l2 = l1 # map ( fun x -> x + 1 ) ; ; |
let rec map_list f ( x ' : a lst ) = if x # null then new nil ( ) else new cons ( f x # hd ) ( map_list f x # tl ) ; ; |
let p1 = ( map_list ( fun x -> new printable_color_point x " red " ) l1 ) ; ; method virtual leq : ' a -> bool end ; ; inherit comparable ( ) val x = x method x = x method leq p = x <= p # x end ; ; inherit int_comparable xi val mutable x ' = xi method set_x y = x ' <- y en... |
let l = new sorted_list ( ) ; ; |
let c = new int_comparable 10 ; ; |
let c2 = new int_comparable2 15 ; ; val mutable x = x method leq ( y : int_comparable ) = x < y # x method x = x method setx y = x <- y end ; ; |
let c3 = new int_comparable3 15 ; ; |
let sort ( l : # comparable list ) = Sort . list ( fun x -> x # leq ) l ; ; |
let pr l = List . map ( fun c -> print_int c # x ; print_string " " ) l ; print_newline ( ) ; ; |
let l = [ new int_comparable 5 ; ( new int_comparable3 2 :> int_comparable ) ; new int_comparable 4 ] ; ; |
let l = [ new int_comparable2 2 ; new int_comparable2 0 ] ; ; |
let min ( x : # comparable ) y = if x # leq y then x else y ; ; val mutable x = x val mutable next = ( None : ' b option ) method x = x method next = next method set_x y = x <- y method set_next l = next <- l method append l = match next with None -> self # set_next l | Some l ' -> l '... |
let rec fold_right f ( l : ' a # link option ) accu = match l with None -> accu | Some l -> f l # x ( fold_right f l # next accu ) ; ; val mutable arg = 0 . val mutable acc = 0 . val mutable equals = function s -> s # arg method arg = arg method acc = acc method enter n = arg <- n ;... |
let calculator = new calculator 0 . 0 . ; ; |
type t = { exn_handler : Continuation . t ; extra_args : ( Simple . t * Flambda_kind . With_subkind . t ) list } type nonrec t = t let print_simple_and_kind ppf ( simple , kind ) = Format . fprintf ppf " [ @< h ( >% a @ \ u { 2237 } @ % a ) ] " @ Simple . print ... |
let create ~ exn_handler ~ extra_args = begin match Continuation . sort exn_handler with | Normal_or_exn -> ( ) | _ -> Misc . fatal_errorf " Continuation % a has wrong sort ( must be [ Normal_or_exn ] ) " Continuation . print exn_handler end ; { exn_handler ; extra_args } |
let exn_handler t = t . exn_handler |
let extra_args t = t . extra_args |
let free_names { exn_handler ; extra_args } = let extra_args = List . map ( fun ( simple , _kind ) -> simple ) extra_args in Name_occurrences . union ( Name_occurrences . singleton_continuation exn_handler ) ( Simple . List . free_names extra_args ) |
let apply_renaming ( { exn_handler ; extra_args } as t ) perm = let exn_handler ' = Renaming . apply_continuation perm exn_handler in let extra_args ' = List . map ( fun ( ( simple , kind ) as extra_arg ) -> let simple ' = Simple . apply_renaming simple perm in if simple == simpl... |
let arity t = let extra_args = List . map ( fun ( _simple , kind ) -> kind ) t . extra_args in let exn_bucket_kind = Flambda_kind . With_subkind . create Flambda_kind . value Anything in Flambda_arity . With_subkinds . create ( exn_bucket_kind :: extra_args ) |
let with_exn_handler t exn_handler = { t with exn_handler } |
let without_extra_args t = { t with extra_args = [ ] } |
let all_ids_for_export { exn_handler ; extra_args } = List . fold_left ( fun ids ( arg , _kind ) -> Ids_for_export . add_simple ids arg ) ( Ids_for_export . add_continuation Ids_for_export . empty exn_handler ) extra_args |
let test_arg_count_mismatch str expected got = test_exn str ( get_exn ( fun ( ) -> arg_count_mismatch expected got ) ) ; ; |
let test_arg_type_mismatch str expected got = test_exn str ( get_exn ( fun ( ) -> arg_type_mismatch expected got ) ) ; ; |
let test_not_applicable str value = test_exn str ( get_exn ( fun ( ) -> not_applicable value ) ) ; ; |
let test_unbound_var str var = test_exn str ( get_exn ( fun ( ) -> unbound_var var ) ) ; ; |
let _ = test_arg_count_mismatch " ( cons 1 2 3 ) " " 2 " 3 ; test_arg_count_mismatch " ( cons 1 ) " " 2 " 1 ; test_arg_count_mismatch " ( ) " / " 1 " + 0 ; test_arg_count_mismatch " ( symbol ) " ? " 1 " 0 ; test_arg_count_mismatch " ( symbol ... |
module Expanded_type : sig type t val of_non_alias_type : ? coercion : Coercion . t -> TG . t -> t val create_value : Type_grammar . head_of_kind_value -> t val create_naked_immediate : Type_grammar . head_of_kind_naked_immediate -> t val create_naked_float : Type_grammar . head_of_kind_naked_float... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.