text
stringlengths
0
601k
let get1 ' = function | ( Cons ( x , _ ) : ( _ * ' a , ' a ) t ) -> x | Nil -> assert false ; ;
type _ t = Int : int -> int t | String : string -> string t | Same : ' l t -> ' l t ; ;
let rec f = function Int x -> x | Same s -> f s ; ;
type ' a tt = ' a t = Int : int -> int tt | String : string -> string tt | Same : ' l1 t -> ' l2 tt ; ;
type _ t = I : int t ; ;
let f ( type a ) ( x : a t ) = let module M = struct let ( I : a t ) = x let x = ( I : a t ) end in ( ) ; ;
type ( _ , _ ) eq = Refl : ( ' a , ' a ) eq ; ;
let bad ( type a ) = let module N = struct module rec M : sig val e : ( int , a ) eq end = struct let ( Refl : ( int , a ) eq ) = M . e let e : ( int , a ) eq = Refl end end in N . M . e ; ;
type ' + a n = private int
type nil = private Nil_type
type ( _ , _ ) elt = | Elt_fine : ' nat n -> ( ' l , ' nat * ' l ) elt | Elt : ' nat n -> ( ' l , ' nat -> ' l ) elt
type _ t = Nil : nil t | Cons : ( ' x , ' fx ) elt * ' x t -> ' fx t ; ;
let undetected : ( ' a -> ' b -> nil ) t -> ' a n -> ' b n -> unit = fun sh i j -> let Cons ( Elt dim , _ ) = sh in ( ) ; ;
type _ t = T : int t ; ;
let _ = match ( raise Not_found : float t ) with _ -> . ; ;
type ( _ , _ ) eq = Eq : ( ' a , ' a ) eq | Neq : int -> ( ' a , ' b ) eq ; ;
let f ( type a ) ( Neq n : ( a , a t ) eq ) = n ; ;
module F ( T : sig type _ t end ) = struct let f ( type a ) ( Neq n : ( a , a T . t ) eq ) = n end ; ;
type _ succ = Succ
type _ nat = | NZ : zero nat | NS : ' a nat -> ' a succ nat
type _ fin = | FZ : ' a succ fin | FS : ' a fin -> ' a succ fin
type _ is_succ = IS : ' a succ is_succ
let fin_succ : type n . n fin -> n is_succ = function | FZ -> IS | FS _ -> IS ; ;
type ' a term = | Var of ' a fin | Leaf | Fork of ' a term * ' a term
let var x = Var x
let lift r : ' m fin -> ' n term = fun x -> Var ( r x )
let rec pre_subst f = function | Var x -> f x | Leaf -> Leaf | Fork ( t1 , t2 ) -> Fork ( pre_subst f t1 , pre_subst f t2 )
let comp_subst f g ( x : ' a fin ) = pre_subst f ( g x ) ; ;
let rec thin : type n . n succ fin -> n fin -> n succ fin = fun x y -> match x , y with | FZ , y -> FS y | FS x , FZ -> FZ | FS x , FS y -> FS ( thin x y )
let bind t f = match t with | None -> None | Some x -> f x
let rec thick : type n . n succ fin -> n succ fin -> n fin option = fun x y -> match x , y with | FZ , FZ -> None | FZ , FS y -> Some y | FS x , FZ -> let IS = fin_succ x in Some FZ | FS x , FS y -> let IS = fin_succ x in bind ( thick x y ) ( fun x -> Some ( FS x ) )
let rec check : type n . n succ fin -> n succ term -> n term option = fun x t -> match t with | Var y -> bind ( thick x y ) ( fun x -> Some ( Var x ) ) | Leaf -> Some Leaf | Fork ( t1 , t2 ) -> bind ( check x t1 ) ( fun t1 -> bind ( check x t2 ) ( fun t2 -> Some ( Fork ( t1 , t2 ) ) ) )
let subst_var x t ' y = match thick x y with | None -> t ' | Some y ' -> Var y '
let subst x t ' = pre_subst ( subst_var x t ' ) ; ;
type ( _ , _ ) alist = | Anil : ( ' n , ' n ) alist | Asnoc : ( ' m , ' n ) alist * ' m term * ' m succ fin -> ( ' m succ , ' n ) alist
let rec sub : type m n . ( m , n ) alist -> m fin -> n term = function | Anil -> var | Asnoc ( s , t , x ) -> comp_subst ( sub s ) ( subst_var x t )
let rec append : type m n l . ( m , n ) alist -> ( l , m ) alist -> ( l , n ) alist = fun r s -> match s with | Anil -> r | Asnoc ( s , t , x ) -> Asnoc ( append r s , t , x )
type _ ealist = EAlist : ( ' a , ' b ) alist -> ' a ealist
let asnoc a t ' x = EAlist ( Asnoc ( a , t ' , x ) )
let rec weaken_fin : type n . n fin -> n succ fin = function | FZ -> FZ | FS x -> FS ( weaken_fin x )
let weaken_term t = pre_subst ( fun x -> Var ( weaken_fin x ) ) t
let rec weaken_alist : type m n . ( m , n ) alist -> ( m succ , n succ ) alist = function | Anil -> Anil | Asnoc ( s , t , x ) -> Asnoc ( weaken_alist s , weaken_term t , weaken_fin x )
let rec sub ' : type m . m ealist -> m fin -> m term = function | EAlist Anil -> var | EAlist ( Asnoc ( s , t , x ) ) -> comp_subst ( sub ' ( EAlist ( weaken_alist s ) ) ) ( fun t ' -> weaken_term ( subst_var x t t ' ) )
let subst ' d = pre_subst ( sub ' d ) ; ;
let flex_flex x y = match thick x y with | Some y ' -> asnoc Anil ( Var y ' ) x | None -> EAlist Anil
let flex_rigid x t = bind ( check x t ) ( fun t ' -> Some ( asnoc Anil t ' x ) )
let rec amgu : type m . m term -> m term -> m ealist -> m ealist option = fun s t acc -> match s , t , acc with | Leaf , Leaf , _ -> Some acc | Leaf , Fork _ , _ -> None | Fork _ , Leaf , _ -> None | Fork ( s1 , s2 ) , Fork ( t1 , t2 ) , _ -> bind ( amgu s1 t1 acc ) ( amgu s2 t2 ) | Var x , Var y , EAlist Anil -> let I...
let mgu s t = amgu s t ( EAlist Anil ) ; ;
let s = Fork ( Var FZ , Fork ( Var ( FS ( FS FZ ) ) , Leaf ) )
let t = Fork ( Var ( FS FZ ) , Var ( FS FZ ) )
let d = match mgu s t with Some x -> x | None -> failwith " mgu "
let s ' = subst ' d s
let t ' = subst ' d t ; ;
type ( _ , _ ) eq = Refl : ( ' a , ' a ) eq
let magic : ' a ' b . ' a -> ' b = fun ( type a b ) ( x : a ) -> let module M = ( functor ( T : sig type ' a t end ) -> struct let f ( Refl : ( a T . t , b T . t ) eq ) = ( x :> b ) end ) ( struct type ' a t = unit end ) in M . f Refl ; ;
type ( _ , + _ ) eq = Refl : ( ' a , ' a ) eq
let magic : ' a ' b . ' a -> ' b = fun ( type a ) ( type b ) ( x : a ) -> let bad_proof ( type a ) = ( Refl : ( < m : a , > < m : a ) > eq :> ( < m : a , > < ) > eq ) in let downcast : type a . ( a , < ) > eq -> < > -> a = fun ( type a ) ( Refl : ( a , < ) > eq ) ( s : < ) > -> ( s :> a ) in ( downcast bad_proof ( ( ob...
type _ t = | IntLit : int t | BoolLit : bool t
let check : type s . s t * s -> bool = function | BoolLit , false -> false | IntLit , 6 -> false ; ;
type ( ' a , ' b ) pair = { fst : ' a ; snd : ' b }
let check : type s . ( s t , s ) pair -> bool = function | { fst = BoolLit ; snd = false } -> false | { fst = IntLit ; snd = 6 } -> false ; ;
module type S = sig type t [ @@ immediate ] end ; ;
module F ( M : S ) : S = M ; ; [ %% expect { |
module type S = sig type t [ @@ immediate ] end
module F : functor ( M : S ) -> S } ] ; ; |
module A = struct type t [ @@ immediate ] type s = t [ @@ immediate ] type r = s type p = q [ @@ immediate ] and q = int end ; ; [ %% expect { |
module A : sig type t [ @@ immediate ] type s = t [ @@ immediate ] type r = s type p = q [ @@ immediate ] and q = int end } ] ; ; |
module type X = sig type t end ; ;
module Y = struct type t = int end ; ;
module Z = ( ( Y : X with type t = int ) : sig type t [ @@ immediate ] end ) ; ; [ %% expect { |
module type X = sig type t end
module Y : sig type t = int end
module Z : sig type t [ @@ immediate ] end } ] ; ; |
module M_valid : S = struct type t = int end ; ;
module FM_valid = F ( struct type t = int end ) ; ; [ %% expect { |
module FM_valid : S } ] ; ; |
module Foo : sig type t val x : t ref end = struct type t = int let x = ref 0 end ; ; [ %% expect { |
module Foo : sig type t val x : t ref end } ] ; ; |
module Bar : sig type t [ @@ immediate ] val x : t ref end = struct type t = int let x = ref 0 end ; ; [ %% expect { |
module Bar : sig type t [ @@ immediate ] val x : t ref end } ] ; ; |
let test f = let start = Sys . time ( ) in f ( ) ; ( Sys . time ( ) . - start ) ; ; [ %% expect { | } ] ; ; |
let test_foo ( ) = for i = 0 to 100_000_000 do Foo . x := ! Foo . x done ; ; [ %% expect { | } ] ; ; |
let test_bar ( ) = for i = 0 to 100_000_000 do Bar . x := ! Bar . x done ; ; [ %% expect { | } ] ; ; |
module B = struct type t = string [ @@ immediate ] end ; ; [ %% expect { | non - pointer types like int or bool } ] ; ; |
module C = struct type t type s = t [ @@ immediate ] end ; ; [ %% expect { | non - pointer types like int or bool } ] ; ; |
module D : sig type t [ @@ immediate ] end = struct type t = string end ; ; [ %% expect { | Modules do not match : sig type t = string end is not included in sig type t [ @@ immediate ] end Type declarations do not match : type t = string is not included in type t [ @@ immediate ] the first is not an immediate type . }...
module M_invalid : S = struct type t = string end ; ;
module FM_invalid = F ( struct type t = string end ) ; ; [ %% expect { | Modules do not match : sig type t = string end is not included in S Type declarations do not match : type t = string is not included in type t [ @@ immediate ] the first is not an immediate type . } ] ; ; |
module E = struct type t = s [ @@ immediate ] and s = string end ; ; [ %% expect { | non - pointer types like int or bool } ] ; ; |
let sort ( type s ) ( module Set : Set . S with type elt = s ) l = Set . elements ( List . fold_right Set . add l Set . empty )
let make_set ( type s ) cmp : ( module Set . S with type elt = s ) = ( module Set . Make ( struct type t = s let compare = cmp end ) )
let sort_cmp ( type s ) cmp = sort ( module Set . Make ( struct type t = s let compare = cmp end ) )
module type S = sig type t val x : t end ; ;
let f ( module M : S with type t = int ) = M . x ; ;
let f ( module M : S with type t = ' a ) = M . x ; ;
let f ( type a ) ( module M : S with type t = a ) = M . x ; ;
type ' a s = { s : ( module S with type t = ' a ) } ; ;
let f { s ( = module M ) } = M . x ; ;
let f ( type a ) ( { s ( = module M ) } : a s ) = M . x ; ;
type s = { s : ( module S with type t = int ) } ; ;