text
stringlengths
0
601k
module type FUNCTOR_F = functor ( T : TYPE ) -> FUNCTOR with type ' a t = T . t * ' a
module type APPLY_F = functor ( S : SEMIGROUP ) -> APPLY with type ' a t = S . t * ' a
module type APPLICATIVE_F = functor ( M : MONOID ) -> APPLICATIVE with type ' a t = M . t * ' a
module type MONAD_F = functor ( M : MONOID ) -> MONAD with type ' a t = M . t * ' a
module type FOLDABLE_F = functor ( T : TYPE ) -> FOLDABLE with type ' a t = T . t * ' a
module type EQ_F = functor ( First : EQ ) ( Second : EQ ) -> EQ with type t = First . t * Second . t
module type SHOW_F = functor ( First : SHOW ) ( Second : SHOW ) -> SHOW with type t = First . t * Second . t
module type TRAVERSABLE_F = functor ( T : TYPE ) ( A : APPLICATIVE ) -> TRAVERSABLE with type ' a t = T . t * ' a and type ' a applicative_t = ' a A . t
module Magma : MAGMA_F = functor ( First : MAGMA ) ( Second : MAGMA ) -> struct type t = First . t * Second . t let append ( a , b ) ( a ' , b ' ) = First . append a a ' , Second . append b b ' end
module Semigroup : SEMIGROUP_F = functor ( First : SEMIGROUP ) ( Second : SEMIGROUP ) -> struct include Magma ( First ) ( Second ) end
module Monoid : MONOID_F = functor ( First : MONOID ) ( Second : MONOID ) -> struct include Semigroup ( First ) ( Second ) let empty = First . empty , Second . empty end
module Functor : FUNCTOR_F = functor ( T : TYPE ) -> struct type ' a t = T . t * ' a let map f ( a , b ) = a , f b end
module Apply : APPLY_F = functor ( S : SEMIGROUP ) -> struct include Functor ( S ) let apply ( a , f ) ( a ' , x ) = S . append a a ' , f x end
module Applicative : APPLICATIVE_F = functor ( M : MONOID ) -> struct include Apply ( M ) let pure a = M . empty , a end
module Monad : MONAD_F = functor ( M : MONOID ) -> struct include Applicative ( M ) let flat_map ( a , b ) f = match f b with | a ' , c -> M . append a a ' , c end
module Foldable : FOLDABLE_F = functor ( T : TYPE ) -> struct type ' a t = T . t * ' a let fold_left f init ( _ , x ) = f init x and fold_right f init ( _ , x ) = f x init module Fold = struct let fold_map f ( _ , x ) = f x end module Fold_Map ( M : MONOID ) = struct include Fold end module Fold_Map_Plus ( P : PLUS ) =...
module Traversable : TRAVERSABLE_F = functor ( T : TYPE ) ( A : APPLICATIVE ) -> struct type ' a t = T . t * ' a and ' a applicative_t = ' a A . t include ( Functor ( T ) : FUNCTOR with type ' a t := ' a t ) include ( Foldable ( T ) : FOLDABLE with type ' a t := ' a t ) let traverse f ( x , y ) = A . map ( fun z -> x ,...
module Eq : EQ_F = functor ( First : EQ ) ( Second : EQ ) -> struct type t = First . t * Second . t let eq ( a , b ) ( a ' , b ' ) = First . eq a a ' && Second . eq b b ' end
module Semigroupoid : SEMIGROUPOID with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let compose ( _ , c ) ( a , _ ) = a , c end
module Show : SHOW_F = functor ( First : SHOW ) ( Second : SHOW ) -> struct type t = First . t * Second . t let show ( a , b ) = " ( " ^ First . show a ^ " , " ^ Second . show b ^ " ) " end
module Bifunctor : BIFUNCTOR with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let bimap f g ( a , b ) = f a , g b end
module Biapply : BIAPPLY with type ( ' a , ' b ) t = ' a * ' b = struct include Bifunctor let biapply ( f , g ) ( a , b ) = f a , g b end
module Biapplicative : BIAPPLICATIVE with type ( ' a , ' b ) t = ' a * ' b = struct include Biapply let bipure a b = a , b end
module Bifoldable : BIFOLDABLE with type ( ' a , ' b ) t = ' a * ' b = struct type ( ' a , ' b ) t = ' a * ' b let bifold_left f g init ( a , b ) = g ( f init a ) b and bifold_right f g init ( a , b ) = f a ( g b init ) module Fold_Map ( M : MONOID ) = struct let fold_map f g ( a , b ) = M . append ( f a ) ( g b ) end ...
module type BITRAVERSABLE_F = functor ( A : APPLICATIVE ) -> BITRAVERSABLE with type ' a applicative_t = ' a A . t and type ( ' a , ' b ) t = ' a * ' b
module Bitraversable : BITRAVERSABLE_F = functor ( A : APPLICATIVE ) -> struct type ( ' a , ' b ) t = ' a * ' b and ' a applicative_t = ' a A . t include ( Bifunctor : BIFUNCTOR with type ( ' a , ' b ) t := ( ' a , ' b ) t ) include ( Bifoldable : BIFOLDABLE with type ( ' a , ' b ) t := ( ' a , ' b ) t ) module I = Inf...
module Infix = struct include Infix . Biapply ( Biapply ) end
module T = Map . Make ( struct type t = name list let compare t1 t2 = Pervasives . compare t1 t2 end )
type result = { ty_name : name ; ty_labels : name list ; }
type return = { def_types : ( name * typ ) Zmisc . Env . t ; table : result T . t ; }
let empty = { def_types = Zmisc . Env . empty ; table = T . empty }
let recordtype ( { def_types = dtypes ; table = table } as return ) ty_list = let ( ty , l_list ) , return = try . find ty_list table , return with | Not_found -> let l_list = List . map ( fun _ -> Zident . fresh " l " ) ty_list in let l_ty_list = List . map2 ( fun l ty -> ( l , ty ) ) l_list ty_list in let ty_name = Z...
let tuple_into_record return e_list = let ty_list = List . map ( fun e -> e . e_typ ) e_list in recordtype return ty_list
let tuplepat_into_record return e_list = recordtype return ty_list
let rec pattern return ( { p_desc = desc } as p ) = match desc with | Ewildpat | Econstpat _ | Econstr0pat _ | Evarpat _ -> p , return | Etuplepat ( p_list ) -> let p_list , return = Zmisc . map_fold pattern return p_list in tuplepat_into_recordpat return p_list | Etypeconstraintpat ( p , ty ) -> let p , return = patte...
let rec expression return ( { e_desc = desc } as e ) = match desc with | Elocal _ | Eglobal _ | Econst _ | Econstr0 _ | Elast _ -> e , return | Eapp ( app , e_arg , e_list ) -> let e_arg , return = expression return e_arg in let e_list , return = Zmisc . map_fold expression return e_list in { e with e_desc = Eapp ( app...
let rec equation return ( { eq_desc = desc } as eq ) = match desc with | EQeq ( p , e ) -> let return , e = expression return e in { eq with eq_desc = EQeq ( p , e ) } , return | EQinit ( x , e ) -> let return , e = expression return e in { eq with eq_desc = EQinit ( x , e ) } , return | EQreset ( eq_list , e ) -> let ...
let local return ( { l_eq = eq_list ; l_env = l_env } as l ) = let eq_list , return = Zmisc . map_fold equation return eq_list in { l with l_eq = eq_list } , return
let let_expression return ( { e_desc = desc } as e ) = match desc with | Elet ( l , e ) -> let l , return = local return l in let e , return = expression return e in { e with e_desc = Elet ( l , e ) } , return | _ -> expression return e
let implementation return impl = match impl . desc with | Eopen _ | Etypedecl _ | Econstdecl _ -> impl , return | Efundecl ( n , ( { f_body = e } as body ) ) -> let e , return = expression return e in { impl with desc = Efundecl ( n , { body with f_body = e } ) } , return
let implementation_list impl_list = let impl_list , return = Zmisc . map_fold implementation empty impl_list in impl_list
let suite = suite " Tuple2 " ( fun ( ) -> test " make " ( fun ( ) -> expect ( Tuple2 . make 3 4 ) 4 |> toEqual ( let open Eq in pair int int ) int ( 3 , 4 ) 4 ) ; test " first " ( fun ( ) -> expect ( Tuple2 . first ( 3 , 4 ) 4 ) 4 |> toEqual ( let open Eq in int ) int 3 ) ; test " second " ( fun ( ) -> expect ( Tuple2 ...
let suite = suite " Tuple3 " ( fun ( ) -> let open Tuple3 in test " make " ( fun ( ) -> expect ( make 3 4 5 ) 5 |> toEqual ( let open Eq in trio int int int ) int ( 3 , 4 , 5 ) 5 ) ; test " first " ( fun ( ) -> expect ( first ( 3 , 4 , 5 ) 5 ) 5 |> toEqual Eq . int 3 ) 3 ; test " second " ( fun ( ) -> expect ( second (...
let test_check_tuple context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from builtins import return_tuple def derp ( ) -> int : a , b = return_tuple ( ) return a + b } | [ ] ; assert_type_errors { | import typing def f ( l : typing . List [ int ] ) -> int : [ a , b ] = l return a ...
let test_tuple_literal_access context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | def foo ( ) -> int : x = ( 0 , " one " , 2 ) return x [ 0 ] } | [ ] ; assert_type_errors { | def foo ( ) -> int : x = ( 0 , " one " , 2 ) return x [ 1 ] } | [ " Incompatible return type [ 7 ] : Expect...
let test_custom_tuple context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | class C : def __getitem__ ( self , index : int ) -> int : self . counter += 1 return self . counter def __init__ ( self ) -> None : self . counter = 0 def foo ( ) -> None : x , y , z = C ( ) reveal_type ( x )...
let test_length context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple def foo ( ) -> None : xs : Tuple [ ( ) ] y = len ( xs ) reveal_type ( y ) } | [ " Revealed type [ - 1 ] : Revealed type for ` y ` is ` int ` . " ] ; ( )
let test_unpacking context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from typing import Tuple def foo ( x : int , xs : Tuple [ str , bool ] ) -> None : y = ( x , * xs ) reveal_type ( y ) } | [ " Revealed type [ - 1 ] : Revealed type for ` y ` is ` Tuple [ int , str , bool ] ` . "...
let test_star_args context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | from pyre_extensions import Unpack from typing import List , Tuple def expect_int ( * args : Unpack [ Tuple [ int , Unpack [ Tuple [ int , . . . ] ] ] ] ) -> None : . . . def main ( xs : List [ int ] ) -> None :...
let ( ) = " tuple " >::: [ " check_tuple " >:: test_check_tuple ; " literal_access " >:: test_tuple_literal_access ; " custom_tuple " >:: test_custom_tuple ; " length " >:: test_length ; " unpacking " >:: test_unpacking ; " star_args " >:: test_star_args ; ] |> Test . run
if n <= 0 then invalid_arg " duplicate n < 0 " else let arr = Array . init n ( fun x -> x ) x in let lst = Array ( . let patt = <: patt < $ tup : Ast . paCom_of_list lst $ >> in <: expr < fun $ patt $ -> $ tup : Ast . exCom_of_list inherit Ast . map as super ; method ! expr e = match e with [ <: expr @ _loc < Tuple . m...
let ( left , right ) = match x with | 0 -> n , 42 | 1 -> 42 , n | _ -> assert false in left - right let ( left , right ) = match x with | 0 -> n , 42 | 1 -> 42 , n | 2 -> 42 - n , 0 | 3 -> 0 , 42 - n | 4 -> n / 2 , n / 2 | 5 -> n , n | _ -> assert false in left - right let ( left , right ) = match x with | " 0 " -> n ,...
let test f n i = let mw_overhead = let a = Gc . minor_words ( ) in let b = Gc . minor_words ( ) in b . - a in let mw = Gc . minor_words ( ) in let k = f n i in assert ( k = 0 ) ; let mw ' = Gc . minor_words ( ) in let delta = int_of_float ( mw ' . - mw . - mw_overhead ) in printf " allocated % d words \ n " delta
let ( ) = let n = 42 in printf " small_match :\ n " ; for i = 0 to 1 do test small_match n i done ; printf " big_match :\ n " ; for i = 0 to 5 do test big_match n i done ; printf " string_match :\ n " ; for i = 0 to 5 do test string_match n ( string_of_int i ) done
let phys_equal = Caml . ( == )
let arch_sixtyfour = Sys . word_size = 64
module Int = struct let num_bits = Int . num_bits let max_value = Caml . max_int let to_string = string_of_int end
let concat l = Base . String . concat ~ sep " " : l
module type S = S
module Pool = struct let grow_capacity ~ capacity ~ old_capacity = match capacity with | None -> if old_capacity = 0 then 1 else old_capacity * 2 | Some capacity -> if capacity <= old_capacity then failwiths ~ here [ :% here ] " Pool . grow got too small capacity " ( ` capacity capacity , ` old_capacity old_capacity ) ...
module Unsafe = struct include Pool let create slots ~ capacity = create_with_dummy slots ~ capacity ~ dummy : None end
module Debug ( Pool : S ) = struct open Pool let check_invariant = ref true let show_messages = ref true let debug name ts arg sexp_of_arg sexp_of_result f = let prefix = " Pool . " in if ! check_invariant then List . iter ts ~ f ( : invariant ignore ) ; if ! show_messages then Debug . eprints ( concat [ prefix ; name ...
module Error_check ( Pool : S ) = struct open Pool module Slots = Slots module Slot = Slot module Pointer = struct type ' slots t = { mutable is_valid : bool ; pointer : ' slots Pointer . t } [ @@ deriving sexp_of , typerep ] let create pointer = { is_valid = true ; pointer } let null ( ) = { is_valid = false ; pointer...
let big = 32 * 1024
let check ~ expected ~ f = Caml_modify . reset ( ) ; f ( ) ; Caml_modify . count ( ) = expected ; ;
let ( ) = let array_imm = Array . init big ~ f : Fn . id in let array_obj = Array . init big ~ f ( : fun i -> ref i ) in let v = ref ( Random . int 42 ) in let array_imm_set ( a : int array ) i ( x : int ) = a . ( i ) <- x in let array_obj_set a i x = a . ( i ) <- x in assert ( check ~ expected : 0 ~ f ( : fun ( ) -> a...
let ( ) = let open Tuple_pool in let p = create Slots . t3 ~ capacity : 3 ~ dummy ( : Pointer . null ( ) , 0 , " " ) in let e = new3 p ( Pointer . null ( ) ) 0 " " in let v = Int . to_string ( Random . int 42 ) in let n = if Obj . is_int ( Obj . repr e ) then 0 else 1 in assert ( check ~ expected : n ~ f ( : fun ( ) ->...
module type S = sig module Slots : Tuple_type . Slots module Slot : Tuple_type . Slot module Pointer : sig type ' slots t [ @@ deriving sexp_of , typerep ] val null : unit -> _ t val is_null : _ t -> bool val phys_compare : ' a t -> ' a t -> int val phys_equal : ' a t -> ' a t -> bool module Id : sig type t [ @@ derivi...
module type Tuple_pool = sig module Tuple_type = Tuple_type module type S = S include S with type ' a Pointer . t = private int module Unsafe : sig include S with type ' a Pointer . t = private int val create : ( ( _ , _ ) Slots . t as ' slots ) -> capacity : int -> ' slots t end module Debug ( Tuple_pool : S ) : sig i...
let get0 ( ) = if Random . bool ( ) then 0 else 0
let get1 ( ) = if Random . bool ( ) then 1 else 1
let f1_0 = Bench . Test . create ~ name " : tuple1_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a , b = match x , y with | 0 , 0 -> 1 , 1 | x , y -> x + 1 , y + 1 in ignore ( a + b ) ) ; ;
let f1_1 = Bench . Test . create ~ name " : tuple1_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a , b = match x , y with | 0 , 0 -> 1 , 1 | x , y -> x + 1 , y + 1 in ignore ( a + b ) ) ; ;
let f2_0 = Bench . Test . create ~ name " : tuple2_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | 0 , 0 -> 1 + 1 | x , y -> x + 1 + y + 1 in ignore a ) ; ;
let f2_1 = Bench . Test . create ~ name " : tuple2_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | 0 , 0 -> 1 + 1 | x , y -> x + 1 + y + 1 in ignore a ) ; ;
let f3 = Bench . Test . create ~ name " : tuple3 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a , b = match x , y with | a , b -> a , b in ignore ( a + b ) ) ; ;
let f4 = Bench . Test . create ~ name " : tuple4 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a , b = x , y in ignore ( a + b ) ) ; ;
let f5 = Bench . Test . create ~ name " : tuple5 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let c = x , y in let a , b = c in ignore ( a + b ) ) ; ;
let f6_0 = Bench . Test . create ~ name " : tuple6_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | _x -> 20 in ignore a ) ; ;
let f6_1 = Bench . Test . create ~ name " : tuple6_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | _x -> 20 in ignore a ) ; ;
let f7_0 = Bench . Test . create ~ name " : tuple7_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | x -> ignore x ; 20 in ignore a ) ; ;
let f7_1 = Bench . Test . create ~ name " : tuple7_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | x -> ignore x ; 20 in ignore a ) ; ;
let f8_0 = Bench . Test . create ~ name " : tuple8_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | a , b -> ignore a ; ignore b ; 20 in ignore a ) ; ;
let f8_1 = Bench . Test . create ~ name " : tuple8_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | 1 , 1 -> 10 | a , b -> ignore a ; ignore b ; 20 in ignore a ) ; ;
let f9_0 = Bench . Test . create ~ name " : tuple9_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | ( 1 , 1 ) as p -> ignore p ; 10 | x , y -> x + y in ignore a ) ; ;
let f9_1 = Bench . Test . create ~ name " : tuple9_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | ( 1 , 1 ) as p -> ignore p ; 10 | x , y -> x + y in ignore a ) ; ;
let f10_0 = Bench . Test . create ~ name " : tuple10_0 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | ( 1 , y ) as p -> ignore p ; 1 + y | x , y -> x + y in ignore a ) ; ;
let f10_1 = Bench . Test . create ~ name " : tuple10_1 " ( let x = get1 ( ) in let y = get1 ( ) in fun ( ) -> let a = match x , y with | ( 1 , y ) as p -> ignore p ; 1 + y | x , y -> x + y in ignore a ) ; ;
let f11 = Bench . Test . create ~ name " : tuple11 " ( let x = get0 ( ) in let y = get0 ( ) in fun ( ) -> let a = match x , y with | ( x , y ) as p -> ignore p ; x + y in ignore a ) ; ;
let tests = [ f1_0 ; f1_1 ; f2_0 ; f2_1 ; f3 ; f4 ; f5 ; f6_0 ; f6_1 ; f7_0 ; f7_1 ; f8_0 ; f8_1 ; f9_0 ; f9_1 ; f10_0 ; f10_1 ; f11 ] ; ;
let command = Bench . make_command tests
module Slots = struct type u_ = { slots_per_tuple : int } [ @@ deriving sexp_of ] type ( ' tuple , ' variant ) u = u_ [ @@ deriving sexp_of ] type t_ = [ ` Slots of u_ ] [ @@ deriving sexp_of ] type ( ' tuple , ' variant ) t = t_ [ @@ deriving sexp_of ] let slots_per_tuple ( ` Slots { slots_per_tuple = n } ) = n type '...
module type Slots = sig type ( ' tuple , ' variant ) u type ( ' tuple , ' variant ) t = [ ` Slots of ( ' tuple , ' variant ) u ] [ @@ deriving sexp_of ] val slots_per_tuple : ( _ , _ ) t -> int type ' a0 t1 = ( ' a0 , [ ` S0 of ' a0 ] ) t [ @@ deriving sexp_of ] type ( ' a0 , ' a1 ) t2 = ( ' a0 * ' a1 , [ ` S0 of ' a0 ...
module type Slot = sig type ( ' variant , ' a ) t [ @@ deriving sexp_of ] val equal : ( ' v , ' a ) t -> ( ' v , ' a ) t -> bool val t0 : ( [ > ` S0 of ' a ] , ' a ) t val t1 : ( [ > ` S1 of ' a ] , ' a ) t val t2 : ( [ > ` S2 of ' a ] , ' a ) t val t3 : ( [ > ` S3 of ' a ] , ' a ) t val t4 : ( [ > ` S4 of ' a ] , ' a ...
let config = { config with site_width = 0 . 25 . * config . site_width ; site_height = 0 . 25 . * config . site_height ; state_height = 0 . 7 . * config . state_height ; state_width = 0 . 7 . * config . state_width ; free_width = 0 . 6 . * config . free_width ; free_height = 0 . 4 . * config . free_height ; bound_heigh...
let build_rule ? mul = let h = match mul with | None -> 0 . 8 | Some f -> 0 . 8 . * f in build_rule ~ hgap ( : Some h ) let [ a , [ a_x , [ ] ; ] ; b , [ b_x , [ ] ; b_y , [ b_y_u ; b_y_p ] ; ] ] , signature = add_in_signature [ " $\ text { \ agent { A } { } } " , [ $ Shape " circle " ; Width ( 0 . 13 . * config . agen...
let [ agent_a , [ site_a , _ ] ; agent_b , [ site_b_x , _ ] ] , couple = add_in_graph [ a , 0 . , 0 . , [ ] , [ a_x , [ ] , [ ] ] ; b , 0 . 6 , 0 . , [ ] , [ b_x , [ ] , [ ] ] ; ] signature
let add_bond s1 s2 graph = let graph = add_link_list [ s1 , s2 ] graph in ( [ ] , [ ] , [ ] ) , graph
let add_free s1 s2 graph = let _ , graph = add_free_list [ s1 , [ ] ; s2 , [ ] ] graph in ( [ ] , [ ] , [ ] ) , graph
let bind ? directives ? file g s1 s2 = build_rule ? directives ? file g ( add_free s1 s2 ) ( add_bond s1 s2 )