text stringlengths 12 786k |
|---|
type piece = piece_kind * int ; ; |
let x = ( X , 0 ) and s = ( S , 0 ) and h = ( H , 0 ) ; ; |
let ( c0 , c1 , c2 , c3 ) = ( ( C , 0 ) , ( C , 1 ) , ( C , 2 ) , ( C , 3 ) ) ; ; |
let ( v0 , v1 , v2 , v3 ) = ( ( V , 0 ) , ( V , 1 ) , ( V , 2 ) , ( V , 3 ) ) ; ; |
let all_pieces : piece list = [ s ; h ; c0 ; c1 ; c2 ; c3 ; v0 ; v1 ; v2 ; v3 ] ; ; |
type board = piece array array ; ; |
let initial_board = [ | [ | v0 ; s ; s ; v1 ] ; | [ | v0 ; s ; s ; v1 ] ; | [ | v2 ; h ; h ; v3 ] ; | [ | v2 ; c0 ; c1 ; v3 ] ; | [ | c2 ; x ; x ; c3 ] | ] | ; ; |
let initial_board_simpler = [ | [ | c2 ; s ; s ; c1 ] | ; [ | c0 ; s ; s ; c3 ] | ; [ | v1 ; v2 ; v3 ; v0 ] | ; [ | v1 ; v2 ; v3 ; v0 ] | ; [ | x ; x ; x ; x ] | ] | ; ; |
let initial_board_trivial = [ | [ | x ; s ; s ; x ] | ; [ | x ; s ; s ; x ] | ; [ | x ; x ; x ; x ] | ; [ | x ; x ; x ; x ] | ; [ | x ; x ; x ; x ] | ] | ; ; |
type direction = { dcol : int ; drow : int ; } ; ; |
type move = Move of piece * direction * board ; ; |
let move _ ( Move ( _ , _ , b ) ) = b ; ; |
let rec loop p f x = if p x then x else loop p f ( f x ) ; ; |
let rec find p = function | [ ] -> raise NotFound | hd :: tl when p hd = true -> hd | _ :: tl -> find p tl ; ; |
let rec exists p l = try ignore ( find p l ) ; true with NotFound -> false ; ; |
let near : int rel = fun x -> [ x - 2 ; x - 1 ; x ; x + 1 ; x + 2 ] ; ; |
let flat_map ( r : ' e rel ) = fun l -> List . concat ( List . map r l ) ; ; |
let rec iter_rel ( r : ' e rel ) ( n : int ) = fun x -> match n with | 0 -> [ x ] | i -> flat_map r ( iter_rel r ( n - 1 ) x ) ; ; |
let solve ( r : ' a rel ) ( p : ' a prop ) ( x : ' a ) = find p ( loop ( exists p ) ( flat_map r ) [ x ] ) ; ; |
let solve_path ( r : ' a rel ) ( p : ' a prop ) ( x : ' a ) = let p ' = fun l -> p ( List . hd l ) and r ' = fun l -> List . map ( fun e -> e :: l ) ( r ( List . hd l ) ) in List . tl ( List . rev ( solve r ' p ' [ x ; x ] ) ) ; ; |
let archive_map ( opset : ( ' a , ' set ) set_operations ) ( r : ' a rel ) ( s , l ) = let rec aux s ' l ' = function | [ ] -> ( s ' , l ' ) | hd :: tl -> if not ( opset . mem hd s ' ) then aux ( opset . add hd s ' ) ( hd :: l ' ) tl else aux s... |
let solve ' ( opset : ( ' a , ' set ) set_operations ) ( r : ' a rel ) ( p : ' a prop ) ( x : ' a ) = let exists ' ( s , l ) = exists p l and find ' ( s , l ) = find p l in find ' ( loop exists ' ( archive_map opset r ) ( opset . empty , [ x ] ... |
let solve_path ' ( opset : ( ' a list , ' set ) set_operations ) ( r : ' a rel ) ( p : ' a prop ) ( x : ' a ) = let p ' = fun l -> p ( List . hd l ) and r ' = fun l -> List . map ( fun e -> e :: l ) ( r ( List . hd l ) ) in List . tl ( List . ... |
let solve_puzzle ( p : ( ' c , ' m ) puzzle ) ( opset : ( ' c list , ' set ) set_operations ) ( c : ' c ) = let r c = List . map ( p . move c ) ( p . possible_moves c ) and pred c = p . final c in solve_path ' opset r pred c ; ; |
let final board = board . ( 3 ) . ( 1 ) = s && board . ( 3 ) . ( 2 ) = s && board . ( 4 ) . ( 1 ) = s && board . ( 4 ) . ( 2 ) = s ; ; |
type location = { row : int ; col : int } ; ; |
let piece_cells ( b : board ) ( p : piece ) = let rec aux accum = function | 20 -> accum | i -> let r = ( i / 4 ) and c = ( i mod 4 ) in if b . ( r ) . ( c ) = p then aux ( { row = r ; col = c } :: accum ) ( i + 1 ) else aux accum ( i + 1 ) in aux [ ... |
let copy_board ( b : board ) = let b ' = [ | [ ] || ; [ ] || ; [ ] || ; [ ] || ; [ ] || ] | in for row = 0 to 4 do b ' . ( row ) <- Array . copy b . ( row ) done ; b ' ; ; |
let move_piece ( b : board ) ( p : piece ) { drow ; dcol } = let in_bounds loc = loc . row >= 0 && loc . row < 5 && loc . col >= 0 && loc . col < 4 and free loc = b . ( loc . row ) . ( loc . col ) = x || b . ( loc . row ) . ( loc . col ) = p in le... |
let possible_moves ( b : board ) = let all_dir = [ { drow = 0 ; dcol = - 1 } ; { drow = 0 ; dcol = 1 } ; { drow = - 1 ; dcol = 0 } ; { drow = 1 ; dcol = 0 } ] and define_move = fun p dir -> match move_piece b p dir with | None -> None | Some b ' -> Some... |
let klotski : ( board , move ) puzzle = { move ; possible_moves ; final } ; ; |
module BoardSet = Set . Make ( struct type t = board let compare b1 b2 = let rec aux r row1 row2 c = let p1 = row1 . ( c ) and p2 = row2 . ( c ) in match p1 , p2 with | ( type1 , num1 ) , ( type2 , num2 ) when type1 = type2 && num1 = num2 -> if c = 3 then if r = 4 then 0 ... |
let solve_klotski initial_board = let opset = { empty = BoardSet . empty ; mem = ( fun l -> BoardSet . mem ( List . hd l ) ) ; add = ( fun l -> BoardSet . add ( List . hd l ) ) } in solve_puzzle klotski opset initial_board ; ; |
let knock = Wcs . dialog_node " Knock " ~ conditions : " true " ~ text : " Knock knock " ( ) |
let who_intent = Wcs . intent " Who " ~ examples : [ " Who ' s there " ; ? " Who is there " ; ? " Who are you " ; ? ] ( ) |
let whoisthere = Wcs . dialog_node " WhoIsThere " ~ conditions_spel : ( Spel . intent who_intent ) ~ text : " Broken Pencil " ~ parent : knock ( ) |
let char_entity = Wcs . entity " Character " ~ values : [ " Broken Pencil " , [ " Damaged Pen " ; " Fractured Pencil " ] ] ( ) |
let answer = Wcs . dialog_node " Answer " ~ conditions_spel : ( Spel . entity char_entity ( ) ) ~ text : " Never mind it ' s pointless " ~ parent : whoisthere ~ context : ( Context . return ( Json . bool true ) ) ( ) |
let fallback = Wcs . dialog_node " Fallback " ~ conditions_spel : Spel . anything_else ~ text : " You should repeat my name " ! ~ previous_sibling : answer ~ next_step : ( whoisthere , Wcs_t . Goto_body ) ( ) |
let ws_knockknock = Wcs . workspace " Knock Knock " ~ entities : [ char_entity ] ~ intents : [ who_intent ] ~ dialog_nodes : [ knock ; whoisthere ; answer ; fallback ; ] ( ) |
let ( ) = print_endline ( Wcs_pretty . workspace ws_knockknock ) |
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 |
type mutable_flag = Immutable | Immutable_unique | Mutable |
type compile_time_constant = | Big_endian | Word_size | Int_size | Max_wosize | Ostype_unix | Ostype_win32 | Ostype_cygwin | Backend_type |
type immediate_or_pointer = | Immediate | Pointer |
type is_safe = | Safe | Unsafe |
type field_read_semantics = | Reads_agree | Reads_vary type alloc_mode = | Alloc_heap | Alloc_local let alloc_heap = Alloc_heap let alloc_local : alloc_mode = if Config . stack_allocation then Alloc_local else Alloc_heap let join_mode a b = match a , b with | Alloc_local , _ | _ , Alloc_local -> ... |
let is_local_mode = function | Alloc_heap -> false | Alloc_local -> true |
let is_heap_mode = function | Alloc_heap -> true | Alloc_local -> false |
let sub_mode a b = match a , b with | Alloc_heap , _ -> true | _ , Alloc_local -> true | Alloc_local , Alloc_heap -> false |
let eq_mode a b = match a , b with | Alloc_heap , Alloc_heap -> true | Alloc_local , Alloc_local -> true | Alloc_heap , Alloc_local -> false | Alloc_local , Alloc_heap -> false |
type initialization_or_assignment = | Assignment of alloc_mode | Heap_initialization | Root_initialization |
type region_close = | Rc_normal | Rc_close_at_apply |
type primitive = | Pidentity | Pbytes_to_string | Pbytes_of_string | Pignore | Prevapply of region_close | Pdirapply of region_close | Pgetglobal of Ident . t | Psetglobal of Ident . t | Pmakeblock of int * mutable_flag * block_shape * alloc_mode | Pmakefloatblock of mutable_flag * alloc_mode | Pfie... |
let equal_boxed_integer x y = match x , y with | Pnativeint , Pnativeint | Pint32 , Pint32 | Pint64 , Pint64 -> true | ( Pnativeint | Pint32 | Pint64 ) , _ -> false |
let rec equal_value_kind x y = match x , y with | Pgenval , Pgenval -> true | Pfloatval , Pfloatval -> true | Pboxedintval bi1 , Pboxedintval bi2 -> equal_boxed_integer bi1 bi2 | Pintval , Pintval -> true | Parrayval elt_kind1 , Parrayval elt_kind2 -> elt_kind1 = elt_kind2 | Pblock { tag = t... |
type structured_constant = Const_base of constant | Const_block of int * structured_constant list | Const_float_array of string list | Const_immstring of string | Const_float_block of string list |
type tailcall_attribute = | Tailcall_expectation of bool | Default_tailcall |
type inline_attribute = | Always_inline | Never_inline | Available_inline | Unroll of int | Default_inline |
type inlined_attribute = | Always_inlined | Never_inlined | Hint_inlined | Unroll of int | Default_inlined |
let equal_inline_attribute ( x : inline_attribute ) ( y : inline_attribute ) = match x , y with | Always_inline , Always_inline | Never_inline , Never_inline | Available_inline , Available_inline | Default_inline , Default_inline -> true | Unroll u , Unroll v -> u = v | ( Always_inline... |
let equal_inlined_attribute ( x : inlined_attribute ) ( y : inlined_attribute ) = match x , y with | Always_inlined , Always_inlined | Never_inlined , Never_inlined | Hint_inlined , Hint_inlined | Default_inlined , Default_inlined -> true | Unroll u , Unroll v -> u = v | ( Always_inlin... |
type probe_desc = { name : string } |
type probe = probe_desc option |
type specialise_attribute = | Always_specialise | Never_specialise | Default_specialise |
let equal_specialise_attribute x y = match x , y with | Always_specialise , Always_specialise | Never_specialise , Never_specialise | Default_specialise , Default_specialise -> true | ( Always_specialise | Never_specialise | Default_specialise ) , _ -> false |
type local_attribute = | Always_local | Never_local | Default_local |
type function_kind = Curried of { nlocal : int } | Tupled |
type let_kind = Strict | Alias | StrictOpt | Variable |
type meth_kind = Self | Public | Cached |
let equal_meth_kind x y = match x , y with | Self , Self -> true | Public , Public -> true | Cached , Cached -> true | ( Self | Public | Cached ) , _ -> false |
type shared_code = ( int * int ) list |
type function_attribute = { inline : inline_attribute ; specialise : specialise_attribute ; local : local_attribute ; is_a_functor : bool ; stub : bool ; } |
type lambda = Lvar of Ident . t | Lconst of structured_constant | Lapply of lambda_apply | Lfunction of lfunction | Llet of let_kind * value_kind * Ident . t * lambda * lambda | Lletrec of ( Ident . t * lambda ) list * lambda | Lprim of primitive * lambda list * scoped_location | Lswitch of la... |
type program = { module_ident : Ident . t ; main_module_block_size : int ; required_globals : Ident . Set . t ; code : lambda } |
let const_int n = Const_base ( Const_int n ) |
let const_unit = const_int 0 |
let lambda_unit = Lconst const_unit |
let check_lfunction fn = let nparams = List . length fn . params in begin match fn . mode , fn . kind with | Alloc_heap , Tupled -> ( ) | Alloc_local , Tupled -> assert false | mode , Curried { nlocal } -> assert ( 0 <= nlocal ) ; assert ( nlocal <= nparams ) ; if not fn .... |
let default_function_attribute = { inline = Default_inline ; specialise = Default_specialise ; local = Default_local ; is_a_functor = false ; stub = false ; } |
let default_stub_attribute = { default_function_attribute with stub = true } |
let make_key e = let count = ref 0 and make_key = Ident . make_key_generator ( ) in let rec tr_rec env e = incr count ; if ! count > max_raw then raise Not_simple ; match e with | Lvar id -> begin try Ident . find_same id env with Not_found -> e end | Lconst ( Const_base ( Const_string _ ) ... |
let name_lambda strict arg fn = match arg with Lvar id -> fn id | _ -> let id = Ident . create_local " let " in Llet ( strict , Pgenval , id , arg , fn id ) |
let name_lambda_list args fn = let rec name_list names = function [ ] -> fn ( List . rev names ) | ( Lvar _ as arg ) :: rem -> name_list ( arg :: names ) rem | arg :: rem -> let id = Ident . create_local " let " in Llet ( Strict , Pgenval , id , arg , name_list ( Lvar id ... |
let iter_opt f = function | None -> ( ) | Some e -> f e |
let shallow_iter ~ tail ~ non_tail : f = function Lvar _ | Lconst _ -> ( ) | Lapply { ap_func = fn ; ap_args = args } -> f fn ; List . iter f args | Lfunction { body } -> f body | Llet ( _str , _k , _id , arg , body ) -> f arg ; tail body | Lletrec ( decl , body )... |
let iter_head_constructor f l = shallow_iter ~ tail : f ~ non_tail : f l |
let rec free_variables = function | Lvar id -> Ident . Set . singleton id | Lconst _ -> Ident . Set . empty | Lapply { ap_func = fn ; ap_args = args } -> free_variables_list ( free_variables fn ) args | Lfunction { body ; params } -> Ident . Set . diff ( free_variables body ) ... |
let raise_count = ref 0 |
let next_raise_count ( ) = incr raise_count ; ! raise_count |
let staticfail = Lstaticraise ( 0 , [ ] ) |
let rec is_guarded = function | Lifthenelse ( _cond , _body , Lstaticraise ( 0 , [ ] ) , _ ) -> true | Llet ( _str , _k , _id , _lam , body ) -> is_guarded body | Levent ( lam , _ev ) -> is_guarded lam | _ -> false |
let rec patch_guarded patch = function | Lifthenelse ( cond , body , Lstaticraise ( 0 , [ ] ) , kind ) -> Lifthenelse ( cond , body , patch , kind ) | Llet ( str , k , id , lam , body ) -> Llet ( str , k , id , lam , patch_guarded patch body ) | Levent ( la... |
let rec transl_address loc = function | Env . Aident id -> if Ident . global id then Lprim ( Pgetglobal id , [ ] , loc ) else Lvar id | Env . Adot ( addr , pos ) -> Lprim ( Pfield ( pos , Reads_agree ) , [ transl_address loc addr ] , loc ) |
let transl_path find loc env path = match find path env with | exception Not_found -> fatal_error ( " Cannot find address for : " ^ ( Path . name path ) ) | addr -> transl_address loc addr |
let transl_module_path loc env path = transl_path Env . find_module_address loc env path |
let transl_value_path loc env path = transl_path Env . find_value_address loc env path |
let transl_extension_path loc env path = transl_path Env . find_constructor_address loc env path |
let transl_class_path loc env path = transl_path Env . find_class_address loc env path |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.