text
stringlengths
0
601k
module PR_4450_2 = struct module type MyT = sig type ' a wrap = My of ' a t and ' a t = private < map : ' b . ( ' a -> ' b ) ' -> b wrap ; . . > val create : ' a list -> ' a t end module MyMap ( X : MyT ) = struct include X class [ ' a ] c l = object ( self ) method map : ' b . ( ' a -> ' b ) -> ' b wrap = fun f -> My ...
module type ORD = sig type t val compare : t -> t -> int end
module type SET = sig type elt type t val iter : ( elt -> unit ) -> t -> unit end
type ' a tree = E | N of ' a tree * ' a * ' a tree
module Bootstrap2 ( MakeDiet : functor ( X : ORD ) -> SET with type t = X . t tree and type elt = X . t ) : SET with type elt = int = struct type elt = int module rec Elt : sig type t = I of int * int | D of int * Diet . t * int val compare : t -> t -> int val iter : ( int -> unit ) -> t -> unit end = struct type t = I...
module rec DirElt : sig type t = DirRoot | DirSub of DirHash . t end = struct type t = DirRoot | DirSub of DirHash . t end : sig type t = DirElt . t end = struct type t = DirElt . t end : sig type t = DirElt . t list end = struct type t = DirCompare . t list end
module PR_4758 = struct module type S = sig end module type Mod = sig module Other : S end module rec A : S = struct end and C : sig include Mod with module Other = A end = struct module Other = A end module C ' = C module F ( X : sig end ) = struct type t end let f ( x : F ( C ) . t ) = ( x : F ( C ' ) . t ) end
module PR_4557 = struct module F ( X : Set . OrderedType ) = struct module rec Mod : sig module XSet : sig type elt = X . t type t = Set . Make ( X ) . t end module XMap : sig type key = X . t type ' a t = ' a Map . Make ( X ) . t end type elt = X . t type t = XSet . t XMap . t val compare : t -> t -> int end = struct ...
module F ( X : Set . OrderedType ) = struct module rec Mod : sig module XSet : sig type elt = X . t type t = Set . Make ( X ) . t end module XMap : sig type key = X . t type ' a t = ' a Map . Make ( X ) . t end type elt = X . t type t = XSet . t XMap . t val compare : t -> t -> int end = struct module XSet = Set . Make...
let test number result expected = if result = expected then Printf . printf " Test % d passed . \ n " number else Printf . printf " Test % d FAILED . \ n " number ; flush stdout
module rec A : sig type t = Leaf of int | Node of ASet . t val compare : t -> t -> int end = struct type t = Leaf of int | Node of ASet . t let compare x y = match ( x , y ) with ( Leaf i , Leaf j ) -> Stdlib . compare i j | ( Leaf i , Node t ) -> - 1 | ( Node s , Leaf j ) -> 1 | ( Node s , Node t ) -> ASet . compare s...
let _ = let x = A . Node ( ASet . add ( A . Leaf 3 ) ( ASet . singleton ( A . Leaf 2 ) ) ) in let y = A . Node ( ASet . add ( A . Leaf 1 ) ( ASet . singleton x ) ) in test 10 ( A . compare x x ) 0 ; test 11 ( A . compare x ( A . Leaf 3 ) ) 1 ; test 12 ( A . compare ( A . Leaf 0 ) x ) ( - 1 ) ; test 13 ( A . compare y y...
module rec Fib : sig val f : int -> int end = struct let f x = if x < 2 then 1 else Fib . f ( x - 1 ) + Fib . f ( x - 2 ) end ; ;
let _ = test 20 ( Fib . f 10 ) 89 ; ;
module rec Fib2 : sig val f : int -> int end = struct let rec g x = Fib2 . f ( x - 1 ) + Fib2 . f ( x - 2 ) and f x = if x < 2 then 1 else g x end ; ;
let _ = test 21 ( Fib2 . f 10 ) 89 ; ;
let _ = let res = try let module A = struct module rec Bad : sig val f : int -> int end = struct let f = let y = Bad . f 5 in fun x -> x + y end end in false with Undefined_recursive_module _ -> true in test 30 res true ; ;
module rec After : sig val x : int end = struct let x = Before . x + 1 end : sig val x : int end = struct let x = 3 end ; ;
let _ = test 40 After . x 4 ; ;
module rec Strengthen : sig type t val f : t -> t end = struct type t = A | B let _ = ( A : Strengthen . t ) let f x = if true then A else Strengthen . f B end ; ;
module rec Strengthen2 : sig type t val f : t -> t module M : sig type u end module R : sig type v end end = struct type t = A | B let _ = ( A : Strengthen2 . t ) let f x = if true then A else Strengthen2 . f B module M = struct type u = C let _ = ( C : Strengthen2 . M . u ) end module rec R : sig type v = Strengthen2 ...
module rec PolyRec : sig type ' a t = Leaf of ' a | Node of ' a list t * ' a list t val depth : ' a t -> int end = struct type ' a t = Leaf of ' a | Node of ' a list t * ' a list t let x = ( PolyRec . Leaf 1 : int t ) let depth = function Leaf x -> 0 | Node ( l , r ) -> 1 + max ( PolyRec . depth l ) ( PolyRec . depth r...
module rec Expr : sig type t = Var of string | Const of int | Add of t * t | Binding of Binding . t * t val make_let : string -> t -> t -> t val fv : t -> StringSet . t val simpl : t -> t end = struct type t = Var of string | Const of int | Add of t * t | Binding of Binding . t * t let make_let id e1 e2 = Binding ( [ i...
let _ = let e = Expr . make_let " x " ( Expr . Add ( Expr . Var " y " , Expr . Const 0 ) ) ( Expr . Var " x " ) in let e ' = Expr . make_let " x " ( Expr . Var " y " ) ( Expr . Var " x " ) in test 50 ( StringSet . elements ( Expr . fv e ) ) [ " y " ] ; test 51 ( Expr . simpl e ) e ' ; ;
module type ORDERED = sig type t val eq : t -> t -> bool val lt : t -> t -> bool val leq : t -> t -> bool end
module type HEAP = sig module Elem : ORDERED type heap val empty : heap val isEmpty : heap -> bool val insert : Elem . t -> heap -> heap val merge : heap -> heap -> heap val findMin : heap -> Elem . t val deleteMin : heap -> heap end
module Bootstrap ( MakeH : functor ( Element : ORDERED ) -> HEAP with module Elem = Element ) ( Element : ORDERED ) : HEAP with module Elem = Element = struct module Elem = Element module rec BE : sig type t = E | H of Elem . t * PrimH . heap val eq : t -> t -> bool val lt : t -> t -> bool val leq : t -> t -> bool end ...
module LeftistHeap ( Element : ORDERED ) : HEAP with module Elem = Element = struct module Elem = Element type heap = E | T of int * Elem . t * heap * heap let rank = function E -> 0 | T ( r , _ , _ , _ ) -> r let make x a b = if rank a >= rank b then T ( rank b + 1 , x , a , b ) else T ( rank a + 1 , x , b , a ) let e...
module Ints = struct type t = int let eq = ( ) = let lt = ( ) < let leq = ( ) <= end ; ;
let _ = let h = List . fold_right C . insert [ 6 ; 4 ; 8 ; 7 ; 3 ; 1 ] C . empty in test 60 ( C . findMin h ) 1 ; test 61 ( C . findMin ( C . deleteMin h ) ) 3 ; test 62 ( C . findMin ( C . deleteMin ( C . deleteMin h ) ) ) 4 ; ;
module rec Class1 : sig class c : object method m : int -> int end end = struct class c = object method m x = if x <= 0 then x else ( new Class2 . d ) # m x end end : sig class d : object method m : int -> int end end = struct class d = object ( self ) inherit Class1 . c as super method m ( x : int ) = super # m 0 end ...
let _ = test 70 ( ( new Class1 . c ) # m 7 ) 0 ; ;
let _ = try let module A = struct module rec BadClass1 : sig class c : object method m : int end end = struct class c = object method m = 123 end end and BadClass2 : sig val x : int end = struct let x = ( new BadClass1 . c ) # m end end in test 71 true false with Undefined_recursive_module _ -> test 71 true true ; ;
module rec Coerce1 : sig val g : int -> int val f : int -> int end = struct module A = ( Coerce1 : sig val f : int -> int end ) let g x = x let f x = if x <= 0 then 1 else A . f ( x - 1 ) * x end ; ;
let _ = test 80 ( Coerce1 . f 10 ) 3628800 ; ;
module CoerceF ( S : sig end ) = struct let f1 ( ) = 1 let f2 ( ) = 2 let f3 ( ) = 3 let f4 ( ) = 4 let f5 ( ) = 5 end
module rec Coerce2 : sig val f1 : unit -> int end = CoerceF ( Coerce3 ) and Coerce3 : sig end = struct end ; ;
let _ = test 81 ( Coerce2 . f1 ( ) ) 1 ; ;
module Coerce4 ( A : sig val f : int -> int end ) = struct let x = 0 let at a = A . f a end
module rec Coerce5 : sig val blabla : int -> int val f : int -> int end = struct let blabla x = 0 let f x = 5 end : sig val at : int -> int end = Coerce4 ( Coerce5 )
let _ = test 82 ( Coerce6 . at 100 ) 5 ; ;
module rec F : sig type t = X of int | Y of int val f : t -> bool end = struct type t = X of int | Y of int let f = function | X _ -> false | _ -> true end ; ;
let _ = test 100 ( F . f ( F . X 1 ) ) false ; test 101 ( F . f ( F . Y 2 ) ) true
module G ( S : sig val x : int Lazy . t end ) = struct include S end
module M1 = struct let x = lazy 3 end
let _ = Lazy . force M1 . x
module rec M2 : sig val x : int Lazy . t end = G ( M1 )
let _ = test 102 ( Lazy . force M2 . x ) 3
module rec M3 : sig val x : int Lazy . t end = G ( M1 )
let _ = test 103 ( Lazy . force M3 . x ) 3
type t = A of { x : int ; mutable y : int } ; ;
let f ( A r ) = r ; ;
let f ( A r ) = r . x ; ;
let f x = A { x ; y = x } ; ;
let f ( A r ) = A { r with y = r . x + 1 } ; ;
let f ( ) = A { a = 1 } ; ;
let f ( ) = A { x = 1 ; y = 3 } ; ;
type _ t = A : { x : ' a ; y : ' b } -> ' a t ; ;
let f ( A { x ; y } ) = A { x ; y = ( ) } ; ;
let f ( A ( { x ; y } as r ) ) = A { x = r . x ; y = r . y } ; ;
module M = struct type ' a t = | A of { x : ' a } | B : { u : ' b } -> unit t ; ; exception Foo of { x : int } ; ; end ; ;
module N : sig type ' b t = ' b M . t = | A of { x : ' b } | B : { u : ' bla } -> unit t exception Foo of { x : int } type ' b t = ' b M . t = | A of { x : ' b } | B : { u : ' z } -> unit t exception Foo = M . Foo end ; ;
module type S = sig exception A of { x : int } end ; ;
module F ( X : sig val x : ( module S ) end ) = struct module A = ( val X . x )
module type S = sig exception A of { x : int } exception A of { x : string } end ; ;
module M = struct exception A of { x : int } exception A of { x : string } end ; ;
module M1 = struct exception A of { x : int } end ; ;
module M = struct include M1 include M1 end ; ;
module type S1 = sig exception A of { x : int } end ; ;
module type S = sig include S1 include S1 end ; ;
module M = struct exception A = M1 . A end ; ;
module X1 = struct type t = . . end ; ;
module X2 = struct type t = . . end ; ;
module Z = struct type X1 . t += A of { x : int } type X2 . t += A of { x : int } end ; ;
type _ c = C : [ ` A ] c
type t = T : { x [ ` :< A ] c } -> t ; ;
let f ( T { x = C } ) = ( ) ; ;
module M : sig type ' a t type u = u t and v = v t val f : int -> u val g : v -> bool type ' a t = ' a type u = int and v = bool let f x = x let g x = x end ; ;
let h ( x : int ) : bool = M . g ( M . f x ) ; ;
type _ t = C : ( ( ( ' a -> ' o ) -> ' o ) -> ( ' b -> ' o ) -> ' o ) t
let f : type a o . ( ( a -> o ) -> o ) t -> ( a -> o ) -> o = fun C k -> k ( fun x -> x ) ; ;
module type T = sig type ' a t end
module Fix ( T : T ) = struct type r = ( ' r T . t as ' r ) end type _ t = X of string | Y : bytes t
let y : string t = Y
let f : string A . t -> unit = function A . X s -> print_endline s
let ( ) = f A . y
module rec A : sig type t type t = { a : unit ; b : unit } let _ = { a = ( ) } end ; ;
type t = [ ` A | ` B ] ; ;
type ' a u = t ; ;
let a : [ < int u ] = ` A ; ;
type ' a s = ' a ; ;
let b : [ < t s ] = ` B ; ;
module Core = struct module Int = struct module T = struct type t = int let compare = compare let ( ) + x y = x + y end include T module Map = Map . Make ( T ) end module Std = struct module Int = Int end end ; ; ; ;
let x = Int . Map . empty ; ;
let y = x + x ; ;
module M = struct type t = A type u = C end
module N = struct type t = B end A ; ; B ; ; C ; ; C ; ;
module L = struct type v = V end V ; ;
module L = struct type v = V end V ; ;
module M1 = struct type u = v and v = t1 end ; ;