text
stringlengths
12
786k
let d = Lazy . force ( lazy ' a ' )
let e = Lazy . force ( lazy ( fun x -> x + 1 ) )
let rec f ( x : int ) : int = g x and g x = f x
let h = Lazy . force ( lazy f )
let i = Lazy . force ( lazy g )
let j = Lazy . force ( lazy 1L )
let k = Lazy . force ( lazy ( 1 , 2 ) )
let l = Lazy . force ( lazy [ | 3 . 14 ] ) |
let m = Lazy . force ( lazy ( Sys . opaque_identity 3 . 14 ) )
let n = Lazy . force ( lazy None )
let p = fun x -> x
let ( ) = Obj . set_field ( Obj . repr o ) 0 ( Obj . repr 3 ) ; Obj . set_field ( Obj . repr p ) 0 ( Obj . repr 3 ) ; Obj . set_field ( Obj . repr q ) 0 ( Obj . repr 3 ) ; Obj . set_field ( Obj . repr r ) 0 ( Obj . repr 3 )
let set v = Obj . set_field ( Obj . repr v ) 0 ( Obj . repr 3 ) [ @@ inline ]
let ( ) = set o
let opaque = Sys . opaque_identity ( 1 , 2 )
let set_opaque = Obj . set_field ( Obj . repr opaque ) 0 ( Obj . repr 3 )
type filesystem = ( string * node ) list | File | Dir of filesystem | Symlink of string list ; ;
let rec print_path = function | [ ] -> ( ) | [ x ] -> ( print_string x ; print_newline ( ) ) | hd :: tl -> print_string ( hd ^ " " ) ; / print_path tl ; ;
let rec print_file lvl name = if lvl = 0 then ( print_string name ; print_newline ( ) ) else ( print_string " | " ; print_file ( lvl - 1 ) name ) ; ;
let rec print_symlink lvl name path = if lvl = 0 then ( print_string ( name ^ " -> " ) ; print_path path ) else ( print_string " | " ; print_symlink ( lvl - 1 ) name path ) ; ;
let rec print_invalid_symlink lvl name = if lvl = 0 then ( print_string ( name ^ " -> " ) ; print_string " INVALID " ; print_newline ( ) ) else ( print_string " | " ; print_invalid_symlink ( lvl - 1 ) name ) ; ;
let rec print_dir lvl name = if lvl = 0 then ( print_string ( " " / ^ name ) ; print_newline ( ) ) else ( print_string " | " ; print_dir ( lvl - 1 ) name ) ; ;
let print_filesystem root = let rec aux lvl = function | [ ] -> ( ) | ( name , node ) :: tl -> match node with | File -> ( print_file lvl name ; aux lvl tl ) | Dir fs -> ( print_dir lvl name ; aux ( lvl + 1 ) fs ; aux lvl tl ) | Symlink path -> ( print_symlink lvl name p...
let rec resolve sym path = let rec aux acc path = match acc , path with | _ , [ ] -> List . rev acc | [ ] , " . . " :: tl -> aux acc tl | _ , " . . " :: tl -> aux ( List . tl acc ) tl | _ , hd :: tl -> aux ( hd :: acc ) tl in aux ( List . tl ( List . ...
let rec file_exists root path = let node_matches ( ( node1_name : string ) , node1 ) ( ( node2_name : string ) , node2 ) = match node1 , node2 with | ( File , File ) | ( Dir _ , Dir _ ) -> node1_name = node2_name | ( _ , _ ) -> false in match path with | [ ] -...
let print_filesystem root = let rec aux abs_path lvl = function | [ ] -> ( ) | ( name , node ) :: tl -> match node with | File -> ( print_file lvl name ; aux abs_path lvl tl ) | Dir fs -> ( print_dir lvl name ; aux ( name :: abs_path ) ( lvl + 1 ) fs ; aux abs_path lvl tl...
type image = int -> int -> bool ; ;
let all_white = fun x y -> false ; ;
let all_black = fun x y -> true ; ;
let checkers = fun x y -> y / 2 mod 2 = x / 2 mod 2 ; ;
let square cx cy s = fun x y -> let minx = cx - s / 2 in let maxx = cx + s / 2 in let miny = cy - s / 2 in let maxy = cy + s / 2 in x >= minx && x <= maxx && y >= miny && y <= maxy ; ;
let disk cx cy r = fun x y -> let x ' = x - cx in let y ' = y - cy in ( x ' * x ' + y ' * y ' ) <= r * r ; ;
type blend = | Image of image | And of blend * blend | Or of blend * blend | Rem of blend * blend ; ;
let display_image width height f_image = for row = 0 to height do for col = 0 to width do match f_image col row with | false -> print_char ' ' | true -> print_char ' ' # done ; print_newline ( ) done ; ;
let rec render blend x y = match blend with | Image b -> b x y | And ( b1 , b2 ) -> ( ( render b1 ) x y ) && ( ( render b2 ) x y ) | Or ( b1 , b2 ) -> ( ( render b1 ) x y ) || ( ( render b2 ) x y ) | Rem ( b1 , b2 ) -> ( ( render b1 ) x y ) && not ( ...
let display_blend width height blend = display_image width height ( render blend ) ; ;
type ' a xlist = { mutable pointer : ' a cell } | Nil | List of ' a * ' a xlist ; ;
let nil ( ) = { pointer = Nil } ; ;
let cons elt rest = { pointer = List ( elt , rest ) } ; ;
let head l = match l . pointer with | Nil -> raise Empty_xlist | List ( hd , tl ) -> hd
let tail l = match l . pointer with | Nil -> raise Empty_xlist | List ( hd , tl ) -> tl
let add a l = l . pointer <- List ( a , { pointer = l . pointer } )
let add a l = match l . pointer with | Nil -> l . pointer <- List ( a , nil ( ) ) | List ( hd , tl ) -> l . pointer <- List ( a , cons hd tl )
let chop l = match l . pointer with | Nil -> raise Empty_xlist | List ( hd , tl ) -> l . pointer <- tl . pointer
let rec append l1 l2 = match l1 . pointer with | Nil -> l1 . pointer <- l2 . pointer | List ( hd , tl ) -> append tl l2
let rec filter p l = match l . pointer with | Nil -> ( ) | List ( hd , tl ) when p hd -> filter p tl | List ( hd , tl ) -> l . pointer <- tl . pointer ; filter p l
module Tree = struct type ' a t = | Leaf of ' a | Node of ' a t * ' a * ' a t module Iterator = struct type ' a path = | Top | Left of ' a path * ' a * ' a t | Right of ' a t * ' a * ' a path type ' a iterator = Loc of ' a t * ' a path exception Fail let go_left ( Loc ( ...
let bfs t = let rec aux results = function | [ ] -> List . rev results | l :: ls -> let results = ( Tree . Iterator . focus l ) :: results in try aux results ( ls @ [ Tree . Iterator . go_first l ; Tree . Iterator . go_second l ] ) with Tree . Iterator . Fail -> aux result...
module type MultiSet_S = sig type ' a t val occurrences : ' a t -> ' a -> int val empty : ' a t val insert : ' a t -> ' a -> ' a t val remove : ' a t -> ' a -> ' a t end
module MultiSet : MultiSet_S = struct type ' a t = ( ' a * int ) list let occurrences s x = try List . assoc x s with Not_found -> 0 let empty = [ ] let insert s x = match occurrences s x with | 0 -> List . sort compare ( ( x , 1 ) :: s ) | i -> List . sort compare ( ( x ...
let letters word = let rec aux s = function | 0 -> s | i -> aux ( MultiSet . insert s word . [ i - 1 ] ) ( i - 1 ) in aux MultiSet . empty ( String . length word ) ; ;
let anagram word1 word2 = letters word1 = letters word2 ; ;
module type DictSig = sig type ( ' key , ' value ) t val empty : ( ' key , ' value ) t val add : ( ' key , ' value ) t -> ' key -> ' value -> ( ' key , ' value ) t exception NotFound val lookup : ( ' key , ' value ) t -> ' key -> ' value val remove : (...
module Dict : DictSig = struct type ( ' key , ' value ) t = | Empty | Node of ( ' key , ' value ) t * ' key * ' value * ( ' key , ' value ) t let empty = Empty let rec add d k v = match d with | Empty -> Node ( Empty , k , v , Empty ) | Node ( l , k ' , v...
module type GenericTrie = sig type ' a char_table type ' a trie = Trie of ' a option * ' a trie char_table val empty : unit -> ' a trie val insert : ' a trie -> string -> ' a -> ' a trie val lookup : ' a trie -> string -> ' a option end
module CharHashedType = struct type t = char let equal c1 c2 = c1 = c2 let hash c = Char . code c end ; ;
module Trie : GenericTrie with type ' a char_table = ' a CharHashtbl . t = struct type ' a char_table = ' a CharHashtbl . t type ' a trie = Trie of ' a option * ' a trie char_table let empty ( ) = Trie ( None , CharHashtbl . create 100 ) let lookup trie w = let rec aux i ( Trie ...
let rec await r = if Atomic . get r then ( ) else ( cpu_relax ( ) ; await r ) = " caml_ml_domain_critical_section "
let go ( ) = let in_crit = Atomic . make false in let woken = Atomic . make false in let d = spawn ( fun ( ) -> critical_section ( fun ( ) -> Atomic . set in_crit true ; wait ( ) ; Atomic . set in_crit false ) ) in await in_crit ; notify ( get_id d ) ; assert ( not ( ...
let ( ) = for i = 1 to 1000 do go ( ) done ; print_endline " ok "
type ' a waiter = { enqueue : ( ' a , exn ) result -> unit ; ctx : Cancel . Fiber_context . t ; }
type ' a t = ' a waiter Lwt_dllist . t
let add_waiter_protected ~ mutex t cb = let w = Lwt_dllist . add_l cb t in Hook . Node_with_mutex ( w , mutex )
let add_waiter t cb = let w = Lwt_dllist . add_l cb t in Hook . Node w
let wake { enqueue ; ctx } r = if Cancel . Fiber_context . clear_cancel_fn ctx then ( enqueue ( Ok r ) ; true ) else false
let wake_all ( t : _ t ) v = try while true do let waiter = Lwt_dllist . take_r t in ignore ( wake waiter v : bool ) done with Lwt_dllist . Empty -> ( )
let rec wake_one t v = match Lwt_dllist . take_opt_r t with | None -> ` Queue_empty | Some waiter -> if wake waiter v then ` Ok else wake_one t v
let await_internal ~ mutex ( t ' : a t ) id ( ctx : Cancel . fiber_context ) enqueue = match Cancel . Fiber_context . get_error ctx with | Some ex -> Option . iter Mutex . unlock mutex ; enqueue ( Error ex ) | None -> let resolved_waiter = ref Hook . null in let enqueue x = Ctf . ...
let await ~ mutex waiters id = Suspend . enter_unchecked ( await_internal ~ mutex waiters id )
let all_equal ~ equal ~ compare ls = Option . value_map ( List . hd ls ) ls ~ default : true ~ f ( : fun h -> List . equal equal [ h ] ( List . find_all_dups ~ compare ls ) ls )
module Make ( Engine : Intf . Engine . S ) S ( Event_router : Intf . Dsl . Event_router_intf with module Engine := Engine ) Engine ( Network_state : Intf . Dsl . Network_state_intf with module Engine := Engine and module Event_router := Event_router ) Event_router = struct open Network_state mo...
let refl = Filename . concat Filename . current_dir_name " reflector . exe "
let ( ) = let oc = Unix . open_process_out ( refl ^ " - i2o " ) in let pid = Unix . process_out_pid oc in let ( pid1 , status1 ) = Unix . waitpid [ WNOHANG ] pid in assert ( pid1 = 0 ) ; assert ( status1 = WEXITED 0 ) ; output_string oc " aa \ n " ; close_out oc ...
module Steps = struct type t = [ ` PerZ of float | ` Flat of int ] let to_int t z = match t with ` PerZ mm -> Int . max 2 ( Float . to_int ( z . / mm ) ) | ` Flat n -> n end
module Edge = struct type t = float -> Vec3 . t let translate p = Fn . compose ( Vec3 . add p ) let scale s = Fn . compose ( Vec3 . scale s ) let mirror ax = Fn . compose ( Vec3 . mirror ax ) let rotate r = Fn . compose ( Vec3 . rotate r ) let rotate_about_pt r p = Fn . compo...
module EdgeDrawer = struct type drawer = Vec3 . t -> Edge . t type t = { top : drawer ; bot : drawer } let make ( ? max_iter = 100 ) ( ? tolerance = 0 . 001 ) ( ~ get_bez : bool -> Vec3 . t -> Edge . t ) Points . { top_left ; top_right ; bot_left ; bot_right ; _ ...
module Edges = struct type t = { top_left : Edge . t ; top_right : Edge . t ; bot_left : Edge . t ; bot_right : Edge . t } [ @@ deriving scad ] let map ~ f t = { top_left = f t . top_left ; top_right = f t . top_right ; bot_left = f t . bot_left ; bot_right = f t . bot...
type config = { d1 : float ; d2 : float ; z_off : float ; thickness : float ; clearance : float ; n_steps : Steps . t ; n_facets : int ; eyelet_config : Eyelet . config option }
let default = { d1 = 2 . ; d2 = 5 . ; z_off = 0 . ; thickness = 3 . 5 ; clearance = 1 . 5 ; n_steps = ` Flat 4 ; n_facets = 1 ; eyelet_config = None }
type t = { scad : Scad . d3 ; start : Points . t ; foot : Points . t ; edge_drawer : EdgeDrawer . t ; edges : Edges . t ; screw : Eyelet . t option }
let swing_face ( ? step = Float . pi . / 24 . ) key_origin face = let quat = Quaternion . make ( KeyHole . Face . direction face ) and free , pivot , rock_z , z_sign = let ortho = Vec3 . ( normalize ( face . points . centre <-> key_origin ) ) in if Float . ( Vec3 . ...
let poly_siding ( ? x_off = 0 . ) ( ? y_off = 0 . ) ( ? z_off = 0 . ) ( ? clearance = 1 . 5 ) ( ? n_steps = ` Flat 4 ) ( ? n_facets = 1 ) ( ? d1 = 2 . ) ( ? d2 = 5 . ) ? thickness ? eyelet_config side ( key : _ KeyHole . t ) = let start_f...
let poly_of_config ? x_off ? y_off { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = poly_siding ~ d1 ~ d2 ? x_off ? y_off ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ? eyelet_config
let column_drop ? z_off ? clearance ? n_steps ? n_facets ? d1 ? d2 ? thickness ? eyelet_config ~ spacing ~ columns side idx = let key , face , hanging = let c : _ Column . t = Map . find_exn columns idx in match side with | ` North -> let key = snd @@ Map . max_elt_exn c . keys in let e...
let drop_of_config ~ spacing { d1 ; d2 ; z_off ; thickness ; clearance ; n_steps ; n_facets ; eyelet_config } = column_drop ~ d1 ~ d2 ~ z_off ~ thickness ~ clearance ~ n_steps ~ n_facets ~ spacing ? eyelet_config
let start_direction { start = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let foot_direction { foot = { top_left ; top_right ; _ } ; _ } = Vec3 . normalize Vec3 . ( top_left <-> top_right )
let to_scad t = t . scad
module Mnemonic = struct let new_random = Bip39 . of_entropy ( Hacl . Rand . gen 32 ) let to_sapling_key mnemonic = let seed_64_to_seed_32 ( seed_64 : bytes ) : bytes = assert ( Bytes . length seed_64 = 64 ) ; let first_32 = Bytes . sub seed_64 0 32 in let second_32 = Bytes . sub ...
let to_uri unencrypted cctxt sapling_key = if unencrypted then Tezos_signer_backends . Unencrypted . make_sapling_key sapling_key >>?= return else Tezos_signer_backends . Encrypted . encrypt_sapling_key cctxt sapling_key
let from_uri ( cctxt : # Client_context . full ) uri = Tezos_signer_backends . Encrypted . decrypt_sapling_key cctxt uri
let register ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) mnemonic name = let sk = Mnemonic . to_sapling_key mnemonic in to_uri unencrypted cctxt sk >>=? fun sk_uri -> let key = { sk = sk_uri ; path = [ Spending_key . child_index sk ] ; addre...
let derive ( cctxt : # Client_context . full ) ( ? force = false ) ( ? unencrypted = false ) src_name dst_name child_index = Sapling_key . find cctxt src_name >>=? fun k -> from_uri cctxt k . sk >>=? fun src_sk -> let child_index = Int32 . of_int child_index in let dst_sk = Spending_key...
let find_vk cctxt name = Sapling_key . find cctxt name >>=? fun k -> from_uri cctxt k . sk >>=? fun sk -> return ( Viewing_key . of_sk sk )
let new_address ( cctxt : # Client_context . full ) name index_opt = Sapling_key . find cctxt name >>=? fun k -> let index = match index_opt with | None -> k . address_index | Some i -> Viewing_key . index_of_int64 ( Int64 . of_int i ) in from_uri cctxt k . sk >>=? fun sk -> return ( V...
let export_vk cctxt name = find_vk cctxt name >>=? fun vk -> return ( Data_encoding . Json . construct Viewing_key . encoding vk )
type locked_key = | Locked of string | Unlocked of ( string * Keypair . t ) t | Hd_account of Mina_numbers . Hd_index . t
type t = { cache : locked_key Public_key . Compressed . Table . t ; path : string }
let get_privkey_filename public_key = Public_key . Compressed . to_base58_check public_key
let get_path { path ; cache } public_key = let filename = Public_key . Compressed . Table . find cache public_key |> Option . bind ~ f ( : function | Locked file | Unlocked ( file , _ ) _ -> Option . return file | Hd_account _ -> Option . return ( Public_key . Compressed . to_base58...