text stringlengths 0 601k |
|---|
let f { s ( = module M ) } = M . x ; ; |
let f { s ( = module M ) } { s ( = module N ) } = M . x + N . x ; ; |
module type S = sig val x : int end ; ; |
let f ( module M : S ) y ( module N : S ) = M . x + y + N . x ; ; |
let m = ( module struct let x = 3 end ) ; ; |
let m = ( module struct let x = 3 end : S ) ; ; |
let ( module M ) = m in M . x ; ; |
let ( module M ) = m ; ; |
module M = ( val m ) ; ; |
module type S ' = sig val f : int -> int end ; ; |
let rec ( module M : S ' ) = ( module struct let f n = if n <= 0 then 1 else n * M . f ( n - 1 ) end : S ' ) |
module type S = sig type t type u val x : t * u end |
let f ( l : ( module S with type t = int and type u = bool ) list ) = ( l :> ( module S with type u = bool ) list ) |
module TypEq : sig type ( ' a , ' b ) t val apply : ( ' a , ' b ) t -> ' a -> ' b val refl : ( ' a , ' a ) t val sym : ( ' a , ' b ) t -> ( ' b , ' a ) t type ( ' a , ' b ) t = ( ' a -> ' b ) * ( ' b -> ' a ) let refl = ( fun x -> x ) , ( fun x -> x ) let apply ( f , _ ) x = f x let sym ( f , g ) = ( g , f ) end |
module rec Typ : sig module type PAIR = sig type t and t1 and t2 val eq : ( t , t1 * t2 ) TypEq . t val t1 : t1 Typ . typ val t2 : t2 Typ . typ end type ' a typ = | Int of ( ' a , int ) TypEq . t | String of ( ' a , string ) TypEq . t | Pair of ( module PAIR with type t = ' a ) |
let int = Typ . Int TypEq . refl |
let str = Typ . String TypEq . refl |
let pair ( type s1 ) ( type s2 ) t1 t2 = let module P = struct type t = s1 * s2 type t1 = s1 type t2 = s2 let eq = TypEq . refl let t1 = t1 let t2 = t2 end in Typ . Pair ( module P ) |
let rec to_string : ' a . ' a Typ . typ -> ' a -> string = fun ( type s ) t x -> match ( t : s typ ) with | Int eq -> Int . to_string ( TypEq . apply eq x ) | String eq -> Printf . sprintf " % S " ( TypEq . apply eq x ) | Pair ( module P ) -> let ( x1 , x2 ) = TypEq . apply P . eq x in Printf . sprintf " ( % s , % s ) ... |
module type MapT = sig include Map . S type data type map val of_t : data t -> map val to_t : map -> data t end |
type ( ' k , ' d , ' m ) map = ( module MapT with type key = ' k and type data = ' d and type map = ' m ) |
let add ( type k ) ( type d ) ( type m ) ( m ( : k , d , m ) map ) x y s = let module M = ( val m : MapT with type key = k and type data = d and type map = m ) in M . of_t ( M . add x y ( M . to_t s ) ) |
module SSMap = struct include Map . Make ( String ) type data = string type map = data t let of_t x = x let to_t x = x end |
let ssmap = ( module SSMap : MapT with type key = string and type data = string and type map = SSMap . map ) ; ; |
let ssmap = ( module struct include SSMap end : MapT with type key = string and type data = string and type map = SSMap . map ) ; ; |
let ssmap = ( let module S = struct include SSMap end in ( module S ) : ( module MapT with type key = string and type data = string and type map = SSMap . map ) ) ; ; |
let ssmap = ( module SSMap : MapT with type key = _ and type data = _ and type map = _ ) ; ; |
let ssmap : ( _ , _ , _ ) map = ( module SSMap ) ; ; |
module Subst = Map . Make ( struct type t = string let compare = compare end ) |
module Names = Set . Make ( struct type t = string let compare = compare end ) |
type var = [ ` Var of string ] |
let subst_var ~ subst : var -> _ = function ` Var s as x -> try Subst . find s subst with Not_found -> x |
let free_var : var -> _ = function ` Var s -> Names . singleton s |
type ' a lambda = [ ` Var of string | ` Abs of string * ' a | ` App of ' a * ' a ] |
let free_lambda ~ free_rec : _ lambda -> _ = function # var as x -> free_var x | ` Abs ( s , t ) -> Names . remove s ( free_rec t ) | ` App ( t1 , t2 ) -> Names . union ( free_rec t1 ) ( free_rec t2 ) |
let map_lambda ~ map_rec : _ lambda -> _ = function # var as x -> x | ` Abs ( s , t ) as l -> let t ' = map_rec t in if t == t ' then l else ` Abs ( s , t ' ) | ` App ( t1 , t2 ) as l -> let t ' 1 = map_rec t1 and t ' 2 = map_rec t2 in if t ' 1 == t1 && t ' 2 == t2 then l else ` App ( t ' 1 , t ' 2 ) |
let next_id = let current = ref 3 in fun ( ) -> incr current ; ! current |
let subst_lambda ~ subst_rec ~ free ~ subst : _ lambda -> _ = function # var as x -> subst_var ~ subst x | ` Abs ( s , t ) as l -> let used = free t in let used_expr = Subst . fold subst ~ init [ ] : ~ f ( : fun ~ key ~ data acc -> if Names . mem s used then data :: acc else acc ) in if List . exists used_expr ~ f ( : ... |
let eval_lambda ~ eval_rec ~ subst l = match map_lambda ~ map_rec : eval_rec l with ` App ( ` Abs ( s , t1 ) , t2 ) -> eval_rec ( subst ~ subst ( : Subst . add ~ key : s ~ data : t2 Subst . empty ) t1 ) | t -> t |
let rec free1 x = free_lambda ~ free_rec : free1 x |
let rec subst1 ~ subst = subst_lambda ~ subst_rec : subst1 ~ free : free1 ~ subst |
let rec eval1 x = eval_lambda ~ eval_rec : eval1 ~ subst : subst1 x |
type ' a expr = [ ` Var of string | ` Num of int | ` Add of ' a * ' a | ` Neg of ' a | ` Mult of ' a * ' a ] |
let free_expr ~ free_rec : _ expr -> _ = function # var as x -> free_var x | ` Num _ -> Names . empty | ` Add ( x , y ) -> Names . union ( free_rec x ) ( free_rec y ) | ` Neg x -> free_rec x | ` Mult ( x , y ) -> Names . union ( free_rec x ) ( free_rec y ) |
let map_expr ~ map_rec : _ expr -> _ = function # var as x -> x | ` Num _ as x -> x | ` Add ( x , y ) as e -> let x ' = map_rec x and y ' = map_rec y in if x == x ' && y == y ' then e else ` Add ( x ' , y ' ) | ` Neg x as e -> let x ' = map_rec x in if x == x ' then e else ` Neg x ' | ` Mult ( x , y ) as e -> let x ' =... |
let subst_expr ~ subst_rec ~ subst : _ expr -> _ = function # var as x -> subst_var ~ subst x | # expr as e -> map_expr ~ map_rec ( : subst_rec ~ subst ) e |
let eval_expr ~ eval_rec e = match map_expr ~ map_rec : eval_rec e with ` Add ( ` Num m , ` Num n ) -> ` Num ( m + n ) | ` Neg ( ` Num n ) -> ` Num ( - n ) | ` Mult ( ` Num m , ` Num n ) -> ` Num ( m * n ) | # expr as e -> e |
let rec free2 x = free_expr ~ free_rec : free2 x |
let rec subst2 ~ subst = subst_expr ~ subst_rec : subst2 ~ subst |
let rec eval2 x = eval_expr ~ eval_rec : eval2 x |
type lexpr = [ ` Var of string | ` Abs of string * lexpr | ` App of lexpr * lexpr | ` Num of int | ` Add of lexpr * lexpr | ` Neg of lexpr | ` Mult of lexpr * lexpr ] |
let rec free : lexpr -> _ = function # lambda as x -> free_lambda ~ free_rec : free x | # expr as x -> free_expr ~ free_rec : free x |
let rec subst ~ subst : s : lexpr -> _ = function # lambda as x -> subst_lambda ~ subst_rec : subst ~ subst : s ~ free x | # expr as x -> subst_expr ~ subst_rec : subst ~ subst : s x |
let rec eval : lexpr -> _ = function # lambda as x -> eval_lambda ~ eval_rec : eval ~ subst x | # expr as x -> eval_expr ~ eval_rec : eval x |
let rec print = function | ` Var id -> print_string id | ` Abs ( id , l ) -> print_string ( " \ " ^ id ^ " . " ) ; print l | ` App ( l1 , l2 ) -> print l1 ; print_string " " ; print l2 | ` Num x -> print_int x | ` Add ( e1 , e2 ) -> print e1 ; print_string " + " ; print e2 | ` Neg e -> print_string " " ; - print e | ` ... |
let ( ) = let e1 = eval1 ( ` App ( ` Abs ( " x " , ` Var " x " ) , ` Var " y " ) ) in let e2 = eval2 ( ` Add ( ` Mult ( ` Num 3 , ` Neg ( ` Num 2 ) ) , ` Var " x " ) ) in let e3 = eval ( ` Add ( ` App ( ` Abs ( " x " , ` Mult ( ` Var " x " , ` Var " x " ) ) , ` Num 2 ) , ` Num 5 ) ) in print e1 ; print_newline ( ) ; pr... |
module Subst = Map . Make ( struct type t = string let compare = compare end ) |
module Names = Set . Make ( struct type t = string let compare = compare end ) |
let lazy_fix make = let rec obj ( ) = make ( lazy ( obj ( ) ) : _ Lazy . t ) in obj ( ) |
let ( ) !! = Lazy . force object method free : x ' : b -> ? y ' : c -> Names . t method subst : sub ' : a Subst . t -> ' b -> ' a method eval : ' b -> ' a end |
type var = [ ` Var of string ] constraint ' a = [ > var ] method subst ~ sub ( ` Var s as x ) = try Subst . find s sub with Not_found -> x method free ( ` Var s ) = Names . singleton s method eval ( # var as v ) = v end |
type ' a lambda = [ ` Var of string | ` Abs of string * ' a | ` App of ' a * ' a ] |
let next_id = let current = ref 3 in fun ( ) -> incr current ; ! current let var : ' a var_ops = new var_ops and free = lazy !! ops # free and subst = lazy !! ops # subst and eval = lazy !! ops # eval in object ( self : ( ' a , ' a lambda ) # ops ) constraint ' a = [ > ' a lambda ] method free = function # var as x -> ... |
let lambda = lazy_fix ( new lambda_ops ) |
type ' a expr = [ ` Var of string | ` Num of int | ` Add of ' a * ' a | ` Neg of ' a | ` Mult of ' a * ' a ] let var : ' a var_ops = new var_ops and free = lazy !! ops # free and subst = lazy !! ops # subst and eval = lazy !! ops # eval in object ( self : ( ' a , ' a expr ) # ops ) constraint ' a = [ > ' a expr ] metho... |
let expr = lazy_fix ( new expr_ops ) |
type ' a lexpr = [ ' a lambda | ' a expr ] let lambda = new lambda_ops ops in let expr = new expr_ops ops in object ( self : ( ' a , ' a lexpr ) # ops ) constraint ' a = [ > ' a lexpr ] method free = function # lambda as x -> lambda # free x | # expr as x -> expr # free x method subst ~ sub = function # lambda as x -> ... |
let lexpr = lazy_fix ( new lexpr_ops ) |
let rec print = function | ` Var id -> print_string id | ` Abs ( id , l ) -> print_string ( " \ " ^ id ^ " . " ) ; print l | ` App ( l1 , l2 ) -> print l1 ; print_string " " ; print l2 | ` Num x -> print_int x | ` Add ( e1 , e2 ) -> print e1 ; print_string " + " ; print e2 | ` Neg e -> print_string " " ; - print e | ` ... |
let ( ) = let e1 = lambda # eval ( ` App ( ` Abs ( " x " , ` Var " x " ) , ` Var " y " ) ) in let e2 = expr # eval ( ` Add ( ` Mult ( ` Num 3 , ` Neg ( ` Num 2 ) ) , ` Var " x " ) ) in let e3 = lexpr # eval ( ` Add ( ` App ( ` Abs ( " x " , ` Mult ( ` Var " x " , ` Var " x " ) ) , ` Num 2 ) , ` Num 5 ) ) in print e1 ; ... |
module Subst = Map . Make ( struct type t = string let compare = compare end ) |
module Names = Set . Make ( struct type t = string let compare = compare end ) |
let lazy_fix make = let rec obj ( ) = make ( lazy ( obj ( ) ) : _ Lazy . t ) in obj ( ) |
let ( ) !! = Lazy . force object method free : ' b -> Names . t method subst : sub ' : a Subst . t -> ' b -> ' a method eval : ' b -> ' a end |
type var = [ ` Var of string ] |
let var = object ( self : ( [ > var ] , var ) # ops ) method subst ~ sub ( ` Var s as x ) = try Subst . find s sub with Not_found -> x method free ( ` Var s ) = Names . singleton s method eval ( # var as v ) = v end |
type ' a lambda = [ ` Var of string | ` Abs of string * ' a | ` App of ' a * ' a ] |
let next_id = let current = ref 3 in fun ( ) -> incr current ; ! current |
let lambda_ops ( ops : ( ' a , ' a ) # ops Lazy . t ) = let free = lazy !! ops # free and subst = lazy !! ops # subst and eval = lazy !! ops # eval in object ( self : ( [ > ' a lambda ] , ' a lambda ) # ops ) method free = function # var as x -> var # free x | ` Abs ( s , t ) -> Names . remove s ( !! free t ) | ` App (... |
let lambda = lazy_fix lambda_ops |
type ' a expr = [ ` Var of string | ` Num of int | ` Add of ' a * ' a | ` Neg of ' a | ` Mult of ' a * ' a ] |
let expr_ops ( ops : ( ' a , ' a ) # ops Lazy . t ) = let free = lazy !! ops # free and subst = lazy !! ops # subst and eval = lazy !! ops # eval in object ( self : ( [ > ' a expr ] , ' a expr ) # ops ) method free = function # var as x -> var # free x | ` Num _ -> Names . empty | ` Add ( x , y ) -> Names . union ( !! ... |
let expr = lazy_fix expr_ops |
type ' a lexpr = [ ' a lambda | ' a expr ] |
let lexpr_ops ( ops : ( ' a , ' a ) # ops Lazy . t ) = let lambda = lambda_ops ops in let expr = expr_ops ops in object ( self : ( [ > ' a lexpr ] , ' a lexpr ) # ops ) method free = function # lambda as x -> lambda # free x | # expr as x -> expr # free x method subst ~ sub = function # lambda as x -> lambda # subst ~ ... |
let lexpr = lazy_fix lexpr_ops |
let rec print = function | ` Var id -> print_string id | ` Abs ( id , l ) -> print_string ( " \ " ^ id ^ " . " ) ; print l | ` App ( l1 , l2 ) -> print l1 ; print_string " " ; print l2 | ` Num x -> print_int x | ` Add ( e1 , e2 ) -> print e1 ; print_string " + " ; print e2 | ` Neg e -> print_string " " ; - print e | ` ... |
let ( ) = let e1 = lambda # eval ( ` App ( ` Abs ( " x " , ` Var " x " ) , ` Var " y " ) ) in let e2 = expr # eval ( ` Add ( ` Mult ( ` Num 3 , ` Neg ( ` Num 2 ) ) , ` Var " x " ) ) in let e3 = lexpr # eval ( ` Add ( ` App ( ` Abs ( " x " , ` Mult ( ` Var " x " , ` Var " x " ) ) , ` Num 2 ) , ` Num 5 ) ) in print e1 ; ... |
type sexp = A of string | L of sexp list |
type ' a t = ' a array |
let _ = fun ( _ : ' a t ) -> ( ) |
let array_of_sexp _ _ = [ | ] | |
let sexp_of_array _ _ = A " foo " |
let sexp_of_int _ = A " 42 " |
let int_of_sexp _ = 42 |
let t_of_sexp : ' a . ( sexp -> ' a ) -> sexp -> ' a t = let _tp_loc = " core_array . ml . t " in fun _of_a -> fun t -> ( array_of_sexp _of_a ) t |
let sexp_of_t : ' a . ( ' a -> sexp ) -> ' a t -> sexp = fun _of_a -> fun v -> ( sexp_of_array _of_a ) v |
module T = struct module Int = struct type t_ = int array let _ = fun ( _ : t_ ) -> ( ) let t__of_sexp : sexp -> t_ = let _tp_loc = " core_array . ml . T . Int . t_ " in fun t -> ( array_of_sexp int_of_sexp ) t let _ = t__of_sexp let sexp_of_t_ : t_ -> sexp = fun v -> ( sexp_of_array sexp_of_int ) v let _ = sexp_of_t_ ... |
module type Permissioned = sig type ( ' a , ' - perms ) t end |
module Permissioned : sig type ( ' a , ' - perms ) t include sig val t_of_sexp : ( sexp -> ' a ) -> ( sexp -> ' perms ) -> sexp -> ( ' a , ' perms ) t val sexp_of_t : ( ' a -> sexp ) -> ( ' perms -> sexp ) -> ( ' a , ' perms ) t -> sexp end module Int : sig type nonrec ' - perms t = ( int , ' perms ) t include sig val ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.