text
stringlengths 0
601k
|
---|
module Operation = struct module T = struct type t = | Set | Let | Unlet | Makunbound | Defvaralias [ @@ deriving enumerate , sexp_of ] end include T let type_ = Value . Type . enum [ % message " variable - change - operation " ] ( module T ) ( ( function | Set -> " set " | Let -> " let " | Unlet -> " unlet " | Makunbound -> " makunbound " | Defvaralias -> " defvaralias " ) >> Symbol . intern >> Symbol . to_value ) ; ; end |
module Event = struct type t = { local_to_buffer : Buffer . t option ; new_value : Value . t ; operation : Operation . t ; variable_changed : Symbol . t } [ @@ deriving sexp_of ] end |
let build_function here f = Defun . lambda here ( Returns Value . Type . unit ) ( let % map_open . Defun ( ) = return ( ) and symbol = required " symbol " Symbol . type_ and newval = required " newval " Value . Type . value and operation = required " operation " Operation . type_ and where = required " where " ( Value . Type . option Buffer . type_ ) in f { Event . local_to_buffer = where ; new_value = newval ; operation ; variable_changed = symbol } ) ; ; |
type t = { symbol : Symbol . t ; watcher : Function . t } |
let add_variable_watcher = Funcall . Wrap . ( " add - variable - watcher " <: Symbol . type_ @-> Function . type_ @-> return nil ) ; ; |
let add here var ~ f = let watcher = build_function here f in add_variable_watcher ( Var . symbol var ) watcher ; { symbol = Var . symbol var ; watcher } ; ; |
let remove_variable_watcher = Funcall . Wrap . ( " remove - variable - watcher " <: Symbol . type_ @-> Function . type_ @-> return nil ) ; ; |
let remove { symbol ; watcher } = remove_variable_watcher symbol watcher |
let test_check_variance context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | def narnia ( ) : pass def foo ( ) -> None : [ narnia ( ) ] + [ 2 ] } | [ " Missing return annotation [ 3 ] : Returning ` None ` but no return type is specified . " ] ; assert_type_errors { | import typing def foo ( input : str ) -> typing . List [ int ] : return typing . cast ( typing . List [ float ] , input ) } | [ " Incompatible return type [ 7 ] : Expected ` List [ int ] ` but got ` List [ float ] ` . " ] ; assert_type_errors { | import typing def foo ( input ) -> typing . List [ int ] : return typing . cast ( typing . List [ unknown ] , input ) } | [ " Missing parameter annotation [ 2 ] : Parameter ` input ` has no type specified . " ; " Incompatible return type [ 7 ] : Expected ` List [ int ] ` but got ` unknown ` . " ; " Unbound name [ 10 ] : Name ` unknown ` is used but not defined in the current scope . " ; ] ; assert_type_errors { | import typing def foo ( a : typing . Mapping [ str , float ] ) -> float : return a [ " a " ] def bar ( x : typing . Dict [ str , int ] ) -> float : return foo ( x ) } | [ ] ; assert_type_errors { | import typing def foo ( d : typing . Dict [ int , typing . Any ] ) -> None : d . update ( { 1 : 1 } ) } | [ " Missing parameter annotation [ 2 ] : Parameter ` d ` must have a type " ^ " that does not contain ` Any ` . " ; ] ; assert_type_errors { | from typing import TypeVar , Generic IV = TypeVar ( ' IV ' ) CV = TypeVar ( ' CV ' , covariant = True ) class A ( Generic [ IV ] ) : pass class B ( A [ CV ] , Generic [ CV ] ) : pass } | [ " Invalid type variance [ 46 ] : The type variable ` Variable [ CV ] ( covariant ) ` is incompatible \ with parent class type variable ` Variable [ IV ] ` because subclasses cannot use more \ permissive type variables than their superclasses . " ; ] ; assert_type_errors { | from typing import TypeVar , Generic IV = TypeVar ( ' IV ' ) CV = TypeVar ( ' CV ' , contravariant = True ) class A ( Generic [ IV ] ) : pass class B ( A [ CV ] , Generic [ CV ] ) : pass } | [ " Invalid type variance [ 46 ] : The type variable ` Variable [ CV ] ( contravariant ) ` is incompatible \ with parent class type variable ` Variable [ IV ] ` because subclasses cannot use more \ permissive type variables than their superclasses . " ; ] ; assert_type_errors { | from typing import TypeVar , Generic CV = TypeVar ( ' CV ' , covariant = True ) CNV = TypeVar ( ' CNV ' , contravariant = True ) class A ( Generic [ CV ] ) : pass class B ( A [ CNV ] , Generic [ CNV ] ) : pass } | [ " Invalid type variance [ 46 ] : The type variable ` Variable [ CNV ] ( contravariant ) ` is \ incompatible with parent class type variable ` Variable [ CV ] ( covariant ) ` because subclasses \ cannot use more permissive type variables than their superclasses . " ; ] ; assert_type_errors { | from typing import TypeVar , Generic CV = TypeVar ( ' CV ' , covariant = True ) CNV = TypeVar ( ' CNV ' , contravariant = True ) class A ( Generic [ CNV ] ) : pass class B ( A [ CV ] , Generic [ CV ] ) : pass } | [ " Invalid type variance [ 46 ] : The type variable ` Variable [ CV ] ( covariant ) ` is incompatible \ with parent class type variable ` Variable [ CNV ] ( contravariant ) ` because subclasses cannot \ use more permissive type variables than their superclasses . " ; ] ; assert_type_errors { | from typing import TypeVar , Generic IV = TypeVar ( ' IV ' ) CV = TypeVar ( ' CV ' , covariant = True ) class A ( Generic [ CV ] ) : pass class B ( A [ IV ] , Generic [ IV ] ) : pass } | [ ] ; assert_type_errors { | from typing import TypeVar , Generic IV = TypeVar ( ' IV ' ) CV = TypeVar ( ' CV ' , contravariant = True ) class A ( Generic [ CV ] ) : pass class B ( A [ IV ] , Generic [ IV ] ) : pass } | [ ] ; assert_type_errors { | from typing import TypeVar , Generic T = TypeVar ( ' T ' ) U = TypeVar ( ' U ' ) V = TypeVar ( ' V ' ) class A ( Generic [ T ] ) : pass class B ( A [ U , V ] , Generic [ U , V ] ) : pass } | [ " Invalid type parameters [ 24 ] : Generic type ` A ` expects 1 type parameter , received 2 . " ] ; assert_type_errors { | from typing import TypeVar , Generic T = TypeVar ( ' T ' ) U = TypeVar ( ' U ' ) V = TypeVar ( ' V ' ) class A ( Generic [ T , U ] ) : pass class B ( A [ V ] , Generic [ V ] ) : pass } | [ " Invalid type parameters [ 24 ] : Generic type ` A ` expects 2 type parameters , received 1 . " ] |
let test_check_literal_variance context = let assert_type_errors = assert_type_errors ~ context in assert_type_errors { | import typing x : typing . List [ float ] = [ ] x = [ 1 ] } | [ ] ; assert_type_errors { | import typing x : typing . List [ float ] = [ ] x = [ y for y in [ 1 , 2 , 3 , 4 ] ] } | [ ] ; assert_type_errors { | import typing def foo ( x : typing . List [ float ] = [ 1 ] ) -> typing . List [ float ] : return x } | [ " Incompatible variable type [ 9 ] : x is declared to have type ` List [ float ] ` but is " ^ " used as type ` List [ int ] ` . " ; ] ; assert_type_errors { | import typing x : typing . List [ float ] = [ ] y : typing . List [ int ] = [ 1 ] x = y } | [ " Incompatible variable type [ 9 ] : x is declared to have type ` List [ float ] ` but is " ^ " used as type ` List [ int ] ` . " ; ] ; assert_type_errors { | import typing x : typing . Dict [ str , float ] = { } x = { " s " : 1 } } | [ ] ; assert_type_errors { | import typing x : typing . Dict [ str , float ] = { } x = { " s " : value for value in [ 1 , 2 , 3 ] } } | [ ] ; assert_type_errors { | import typing x : typing . Dict [ str , float ] = { } x = { " s " : " " } } | [ " Incompatible variable type [ 9 ] : x is declared to have type ` Dict [ str , float ] ` but " ^ " is used as type ` Dict [ str , str ] ` . " ; ] ; assert_type_errors { | import typing x : typing . Dict [ str , float ] = { " s " : 1 } y : typing . Dict [ str , int ] = { " s " : 1 } x = y } | [ " Incompatible variable type [ 9 ] : x is declared to have type ` Dict [ str , float ] ` but " ^ " is used as type ` Dict [ str , int ] ` . " ; ] ; assert_type_errors { | import typing class Foo ( ) : x : typing . List [ float ] = [ ] y : typing . List [ int ] = [ 1 ] z = Foo ( ) z . x = y } | [ " Incompatible attribute type [ 8 ] : Attribute ` x ` declared in class ` Foo ` has type \ ` List [ float ] ` but is used as type ` List [ int ] ` . " ; ] ; assert_type_errors { | import typing def foo ( ) -> typing . List [ float ] : return [ 1 ] } | [ ] ; assert_type_errors { | import typing def foo ( ) -> typing . List [ float ] : a = [ 1 ] return a } | [ " Incompatible return type [ 7 ] : Expected ` List [ float ] ` but got ` List [ int ] ` . " ] ; assert_type_errors { | import typing def foo ( ) -> typing . Dict [ float , float ] : return { 1 : 1 } } | [ ] ; assert_type_errors { | import typing def foo ( ) -> typing . Dict [ float , float ] : a = { 1 : 1 } return a } | [ " Incompatible return type [ 7 ] : Expected ` Dict [ float , float ] ` but got ` Dict [ int , int ] ` . " ] ; assert_type_errors { | import typing def foo ( ) -> typing . Set [ float ] : return { 1 } } | [ ] ; assert_type_errors { | import typing def foo ( ) -> typing . Set [ float ] : return { x for x in [ 1 , 2 , 3 ] } } | [ ] ; assert_type_errors { | import typing def foo ( ) -> typing . Set [ float ] : a = { 1 } return a } | [ " Incompatible return type [ 7 ] : Expected ` Set [ float ] ` but got ` Set [ int ] ` . " ] ; assert_type_errors { | import typing def foo ( a : typing . List [ float ] ) -> float : return a [ 0 ] def bar ( ) -> float : return foo ( [ 1 , 2 , 3 ] ) } | [ ] ; assert_type_errors { | import typing def foo ( a : typing . List [ float ] ) -> float : return a [ 0 ] def bar ( ) -> float : a = [ 1 , 2 , 3 ] return foo ( a ) } | [ " Incompatible parameter type [ 6 ] : In call ` foo ` , for 1st positional only parameter expected \ ` List [ float ] ` but got ` List [ int ] ` . " ; ] ; assert_type_errors ~ show_error_traces : true { | import typing def foo ( a : typing . List [ float ] ) -> float : return a [ 0 ] def bar ( ) -> float : a = [ 1 , 2 , 3 ] return foo ( a ) } | [ " Incompatible parameter type [ 6 ] : In call ` foo ` , for 1st positional only parameter expected \ ` List [ float ] ` but got ` List [ int ] ` . This call might modify the type of the parameter . See \ https :// pyre - check . org / docs / errors # covariance - and - contravariance for mutable container \ errors . " ; ] ; assert_type_errors { | import typing def foo ( a : typing . Dict [ str , float ] ) -> float : return a [ " a " ] def bar ( ) -> float : return foo ( { " a " : 1 } ) } | [ ] ; assert_type_errors { | import typing def foo ( a : typing . Dict [ str , float ] ) -> float : return a [ " a " ] def bar ( ) -> float : a = { " a " : 1 } return foo ( a ) } | [ " Incompatible parameter type [ 6 ] : In call ` foo ` , for 1st positional only parameter expected \ ` Dict [ str , float ] ` but got ` Dict [ str , int ] ` . " ; ] |
let ( ) = " variance " >::: [ " check_variance " >:: test_check_variance ; " check_literal_variance " >:: test_check_literal_variance ; ] |> Test . run |
module rec X : sig type t = int * bool type t = A | B let f = function A | B -> 0 end ; ; [ %% expect { | Modules do not match : sig type t = X . t = A | B val f : t -> int end is not included in sig type t = int * bool end Type declarations do not match : type t = X . t = A | B is not included in type t = int * bool } ] ; ; | |
module Make ( X : sig val f : [ ` A ] -> unit end ) = struct let make f1 f2 arg = match arg with ` A -> f1 arg ; f2 arg let f = make X . f ( fun _ -> ( ) ) end ; ; [ %% expect { | |
module Make : functor ( X : sig val f : [ ` A ] -> unit end ) -> sig val make : ( ( [ < ` A ] as ' a ) -> ' b ) -> ( ' a -> ' c ) -> ' a -> ' c val f : [ ` A ] -> unit end } ] | |
type ( ' a , ' b ) def = X of int constraint ' b = [ > ` A ] |
type arity = ( int , [ ` A ] ) def = X of int ; ; [ %% expect { | |
type ( ' a , ' b ) def = X of int constraint ' b = [ > ` A ] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( int , [ ` A ] ) def They have different arities . } ] | |
type ( ' a , ' b ) ct = ( int , ' b ) def = X of int ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( int , [ > ` A ] ) def Their constraints differ . } ] | |
type ( ' a , ' b ) kind = ( ' a , ' b ) def = { a : int } constraint ' b = [ > ` A ] ; ; [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ( ' a , [ > ` A ] ) def Their kinds differ . } ] | |
type d = X of int | Y of int |
type missing = d = X of int [ %% expect { | |
type d = X of int | Y of int ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The constructor Y is only present in the original definition . } ] | |
type wrong_type = d = X of float [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Constructors do not match : X of int is not compatible with : X of float The types are not equal . } ] | |
type unboxed = d = X of float [ @@ unboxed ] [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Their internal representations differ : this definition uses unboxed representation . } ] | |
type perm = d = Y of int | X of int [ %% expect { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Constructors number 1 have different names , X and Y . } ] | |
module M : sig type t = Foo of int type t = Foo : int -> t end ; ; [ %% expect { | Modules do not match : sig type t = Foo : int -> t end is not included in sig type t = Foo of int end Type declarations do not match : type t = Foo : int -> t is not included in type t = Foo of int Constructors do not match : Foo : int -> t is not compatible with : Foo of int The first has explicit return type and the second doesn ' t . } ] | |
type ' a u = [ < ` a of int | ` b of bool & int & string > ` a ] as ' a |
type ' a u1 = [ > ` a of int ] as ' a |
type u2 = [ ` a of int ] |
type ' a u3 = [ < ` b | ` a of & int & bool ] as ' a |
type ' a u4 = [ < ` b | ` a of int & bool ] as ' a |
module M1 : sig type t = | Foo of int * int type t = | Foo of float * int end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float * int end is not included in sig type t = Foo of int * int end Type declarations do not match : type t = Foo of float * int is not included in type t = Foo of int * int Constructors do not match : Foo of float * int is not compatible with : Foo of int * int The types are not equal . } ] ; ; | |
module M2 : sig type t = | Foo of int * int type t = | Foo of float end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float end is not included in sig type t = Foo of int * int end Type declarations do not match : type t = Foo of float is not included in type t = Foo of int * int Constructors do not match : Foo of float is not compatible with : Foo of int * int They have different arities . } ] ; ; | |
module M3 : sig type t = | Foo of { x : int ; y : int } type t = | Foo of { x : float ; y : int } end ; ; [ %% expect { | Modules do not match : sig type t = Foo of { x : float ; y : int ; } end is not included in sig type t = Foo of { x : int ; y : int ; } end Type declarations do not match : type t = Foo of { x : float ; y : int ; } is not included in type t = Foo of { x : int ; y : int ; } Constructors do not match : Foo of { x : float ; y : int ; } is not compatible with : Foo of { x : int ; y : int ; } Fields do not match : x : float ; is not compatible with : x : int ; The types are not equal . } ] ; ; | |
module M4 : sig type t = | Foo of { x : int ; y : int } type t = | Foo of float end ; ; [ %% expect { | Modules do not match : sig type t = Foo of float end is not included in sig type t = Foo of { x : int ; y : int ; } end Type declarations do not match : type t = Foo of float is not included in type t = Foo of { x : int ; y : int ; } Constructors do not match : Foo of float is not compatible with : Foo of { x : int ; y : int ; } The second uses inline records and the first doesn ' t . } ] ; ; | |
module M5 : sig type ' a t = | Foo : int -> int t type ' a t = | Foo of ' a end ; ; [ %% expect { | Modules do not match : sig type ' a t = Foo of ' a end is not included in sig type ' a t = Foo : int -> int t end Type declarations do not match : type ' a t = Foo of ' a is not included in type ' a t = Foo : int -> int t Constructors do not match : Foo of ' a is not compatible with : Foo : int -> int t The second has explicit return type and the first doesn ' t . } ] ; ; | |
module M : sig type ( ' a , ' b ) t = A of ' a type ( ' a , ' b ) t = A of ' b end ; ; Modules do not match : sig type ( ' a , ' b ) t = A of ' b end is not included in sig type ( ' a , ' b ) t = A of ' a end Type declarations do not match : type ( ' a , ' b ) t = A of ' b is not included in type ( ' a , ' b ) t = A of ' a Constructors do not match : A of ' b is not compatible with : A of ' a The types are not equal . } ] ; ; | |
module M : sig type ( ' a , ' b ) t = A of ' a type ( ' b , ' a ) t = A of ' a end ; ; Modules do not match : sig type ( ' b , ' a ) t = A of ' a end is not included in sig type ( ' a , ' b ) t = A of ' a end Type declarations do not match : type ( ' b , ' a ) t = A of ' a is not included in type ( ' a , ' b ) t = A of ' a Constructors do not match : A of ' a is not compatible with : A of ' a The types are not equal . } ] ; ; | |
module M ( X : sig type ' a t end ) = struct module Tag_internal = struct type ( ' variant , ' args ) create = | Args of ( ' args -> ' variant ) | Const of ' variant type ( ' variant , ' args ) t = { label : string ; rep : ' args X . t ; arity : int ; args_labels : string list ; index : int ; ocaml_repr : int ; tyid : ' args Typename . t ; create : ( ' variant , ' args ) create } end module Tag : sig type ( ' variant , ' args ) create = | Args of ( ' args -> ' variant ) | Const of ' variant type ( ' variant , ' args ) t val label : ( _ , _ ) t -> string val arity : ( _ , _ ) t -> int val args_labels : ( _ , _ ) t -> string list | B | C of int | D of char | E of { x : int } ] } ) * val index : ( _ , _ ) t -> int print_int ( Obj . magic ' foo ) Standards variants : ------------------- [ ocaml_repr ] is the tag corresponding to the constructor within the type . the way it works in the ocaml runtime is by partitioning the constructors regarding if they have some arguments or not , preserving the order , then assign increasing index withing each partition . Example : { [ type t = | A | B of int | C | D of ( float * string ) | E | F | G of string | H of { x : int } ] } ) * val ocaml_repr : ( _ , _ ) t -> int val create : ( ' variant , ' args ) t -> ( ' variant , ' args ) create val tyid : ( _ , ' args ) t -> ' args Typename . t val traverse : ( _ , ' args ) t -> ' args X . t val internal_use_only : ( ' a , ' b ) Tag_internal . t -> ( ' a , ' b ) t end = struct include Tag_internal let label t = t . label let arity t = t . arity let args_labels t = t . args_labels let index t = t . index let ocaml_repr t = t . ocaml_repr let create t = t . create let tyid t = t . tyid let traverse t = t . rep let internal_use_only t = t end module Variant_internal = struct type _ tag = Tag : ( ' variant , ' a ) Tag . t -> ' variant tag type _ value = Value : ( ' variant , ' a ) Tag . t * ' a -> ' variant value type ' a t = { typename : ' a Typename . t ; tags : ' a tag array ; polymorphic : bool ; value : ' a -> ' a value } end module Variant : sig type _ tag = Tag : ( ' variant , ' args ) Tag . t -> ' variant tag type _ value = Value : ( ' variant , ' args ) Tag . t * ' args -> ' variant value type ' a t val typename_of_t : ' a t -> ' a Typename . t val length : ' a t -> int val tag : ' a t -> int -> ' a tag val is_polymorphic : _ t -> bool val value : ' a t -> ' a -> ' a value val fold : ' a t -> init ' : acc -> f ( ' : acc -> ' a tag -> ' acc ) -> ' acc val internal_use_only : ' a Variant_internal . t -> ' a t end = struct include Variant_internal let typename_of_t t = t . typename let length t = Array . length t . tags let tag t index = t . tags . ( index ) let is_polymorphic t = t . polymorphic let value t = t . value let fold t ~ init ~ f = Array . fold_left f init t . tags let internal_use_only t = t end module Field_internal = struct type ( ' record , ' field ) t = { label : string ; rep : ' field X . t ; index : int ; tyid : ' field Typename . t ; get : ' record -> ' field ; is_mutable : bool } end module Field : sig type ( ' record , ' field ) t foo : string ; bar : float ; } ] } ) * val label : ( _ , _ ) t -> string foo : string ; bar : string ; } ] } ) * val index : ( _ , _ ) t -> int val get : ( ' record , ' field ) t -> ' record -> ' field val is_mutable : ( _ , _ ) t -> bool val tyid : ( _ , ' field ) t -> ' field Typename . t val traverse : ( _ , ' field ) t -> ' field X . t val internal_use_only : ( ' a , ' b ) Field_internal . t -> ( ' a , ' b ) t end = struct include Field_internal let label t = t . label let index t = t . index let get t = t . get let is_mutable t = t . is_mutable let tyid t = t . tyid let traverse t = t . rep let internal_use_only t = t end module Record_internal = struct type _ field = Field : ( ' record , ' a ) Field . t -> ' record field type ' record fields = { get : ' field . ( ' record , ' field ) Field . t -> ' field } type ' a t = { typename : ' a Typename . t ; fields : ' a field array ; has_double_array_tag : bool ; create : ' a fields -> ' a } end module Record : sig type _ field = Field : ( ' record , ' a ) Field . t -> ' record field type ' record fields = { get : ' field . ( ' record , ' field ) Field . t -> ' field } type ' a t val typename_of_t : ' a t -> ' a Typename . t val length : ' a t -> int val field : ' a t -> int -> ' a field val has_double_array_tag : _ t -> bool val create : ' a t -> ' a fields -> ' a val fold : ' a t -> init ' : acc -> f ( ' : acc -> ' a field -> ' acc ) -> ' acc val internal_use_only : ' a Record_internal . t -> ' a t end = struct include Record_internal let typename_of_t t = t . typename let length t = Array . length t . fields let field t index = t . fields . ( index ) let has_double_array_tag t = t . has_double_array_tag let create t = t . create let fold t ~ init ~ f = Array . fold_left f init t . fields let internal_use_only t = t end end |
module type S = sig type ' a t include module type of M ( struct type ' a rep = ' a t type ' a t = ' a rep end ) end |
let decvarint ( s : string ) string : int64 = let dec = D . of_string s in D . int64_as_varint dec |
let encvarint ( i : int64 ) int64 : string = let enc = E . create ( create ) create in E . int64_as_varint i enc ; E . to_string enc |
let str_to_l s = let l = ref [ ] in String . iter ( fun x -> l := x :: ! l ) l s ; List . rev ! l |
let str_to_il s = str_to_l s |> List . map Char . code |
let ( ) = let s = encvarint 12L in assert ( str_to_il s = [ 12 ] 12 ) 12 ; assert ( decvarint s = 12L ) 12L |
let ( ) = let s = encvarint 0L in assert ( str_to_il s = [ 0 ] 0 ) 0 ; assert ( decvarint s = 0L ) 0L |
let ( ) = let s = encvarint 127L in assert ( str_to_il s = [ 127 ] 127 ) 127 ; assert ( decvarint s = 127L ) 127L |
let ( ) = let s = encvarint 128L in assert ( str_to_il s = [ 128 ; 1 ] 1 ) 1 ; assert ( decvarint s = 128L ) 128L |
let ( ) = let s = encvarint 300L in assert ( str_to_il s = [ 0b1010_1100 ; 0b0000_0010 ] 0b0000_0010 ) 0b0000_0010 ; assert ( decvarint s = 300L ) 300L |
let ( ) = let s = encvarint 150L in assert ( str_to_il s = [ 0x96 ; 1 ] 1 ) 1 ; assert ( decvarint s = 150L ) 150L |
let ( ) = let s = encvarint 178282982111149L in assert ( str_to_il s = [ 173 ; 239 ; 197 ; 238 ; 219 ; 196 ; 40 ] 40 ) 40 ; assert ( decvarint s = 178282982111149L ) 178282982111149L |
let setupMethod = ref pointer |
let derefMethod = ref drawarray |
let setupPointers ( ) = let vertices = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 25 . ; 25 . ; 100 . ; 325 . ; 175 . ; 25 . ; 175 . ; 325 . ; 250 . ; 25 . ; 325 . ; 325 . ; ] | and colors = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . 0 ; 0 . 2 ; 0 . 2 ; 0 . 2 ; 0 . 2 ; 1 . 0 ; 0 . 8 ; 1 . 0 ; 0 . 2 ; 0 . 75 ; 0 . 75 ; 0 . 75 ; 0 . 35 ; 0 . 35 ; 0 . 35 ; 0 . 5 ; 0 . 5 ; 0 . 5 ; ] | in glEnableClientState GL_VERTEX_ARRAY ; glEnableClientState GL_COLOR_ARRAY ; glVertexPointer 2 Coord . GL_FLOAT 0 vertices ; glColorPointer 3 Color . GL_FLOAT 0 colors ; ; ; |
let setupInterleave ( ) = let intertwined = Bigarray . Array1 . of_array Bigarray . float32 Bigarray . c_layout [ | 1 . 0 ; 0 . 2 ; 1 . 0 ; 100 . 0 ; 100 . 0 ; 0 . 0 ; 1 . 0 ; 0 . 2 ; 0 . 2 ; 0 . 0 ; 200 . 0 ; 0 . 0 ; 1 . 0 ; 1 . 0 ; 0 . 2 ; 100 . 0 ; 300 . 0 ; 0 . 0 ; 0 . 2 ; 1 . 0 ; 0 . 2 ; 200 . 0 ; 300 . 0 ; 0 . 0 ; 0 . 2 ; 1 . 0 ; 1 . 0 ; 300 . 0 ; 200 . 0 ; 0 . 0 ; 0 . 2 ; 0 . 2 ; 1 . 0 ; 200 . 0 ; 100 . 0 ; 0 . 0 ; ] | in glInterleavedArrays GL_C3F_V3F 0 intertwined ; ; ; |
let init ( ) = glClearColor 0 . 0 0 . 0 0 . 0 0 . 0 ; glShadeModel GL_SMOOTH ; setupPointers ( ) ; ; ; |
let display ( ) = glClear [ GL_COLOR_BUFFER_BIT ] ; if ( ! derefMethod = drawarray ) then glDrawArrays GL_TRIANGLES 0 6 else if ( ! derefMethod = arrayelement ) then begin glBegin GL_TRIANGLES ; glArrayElement 2 ; glArrayElement 3 ; glArrayElement 5 ; glEnd ( ) ; end else if ( ! derefMethod = drawelements ) then begin let indices = Bigarray . Array1 . of_array Bigarray . nativeint Bigarray . c_layout [ | 0n ; 1n ; 3n ; 4n ] | in glDrawElements GL_POLYGON 4 Elem . GL_UNSIGNED_INT indices ; end ; glFlush ( ) ; ; ; |
let reshape ~ width : w ~ height : h = glViewport 0 0 w h ; glMatrixMode GL_PROJECTION ; glLoadIdentity ( ) ; gluOrtho2D 0 . 0 ( float w ) 0 . 0 ( float h ) ; ; ; |
let mouse ~ button ~ state ~ x ~ y = match button , state with | GLUT_LEFT_BUTTON , GLUT_DOWN -> if ( ! setupMethod = pointer ) then begin setupMethod := interleaved ; setupInterleave ( ) ; end else if ( ! setupMethod = interleaved ) then begin setupMethod := pointer ; setupPointers ( ) ; end ; glutPostRedisplay ( ) ; | GLUT_MIDDLE_BUTTON , GLUT_DOWN | GLUT_RIGHT_BUTTON , GLUT_DOWN -> if ( ! derefMethod = drawarray ) then derefMethod := arrayelement else if ( ! derefMethod = arrayelement ) then derefMethod := drawelements else if ( ! derefMethod = drawelements ) then derefMethod := drawarray ; glutPostRedisplay ( ) ; | _ -> ( ) ; ; |
let keyboard ~ key ~ x ~ y = match key with | ' \ 027 ' -> exit 0 ; | _ -> ( ) ; ; |
let ( ) = ignore ( glutInit Sys . argv ) ; glutInitDisplayMode [ GLUT_SINGLE ; GLUT_RGB ] ; glutInitWindowSize 350 350 ; glutInitWindowPosition 100 100 ; ignore ( glutCreateWindow Sys . argv . ( 0 ) ) ; let gl_version = glGetString GL_VERSION in if gl_version < " 1 . 1 " then begin Printf . eprintf " This program demonstrates a feature which is not in OpenGL Version 1 . 0 . \ n \ If your implementation of OpenGL Version 1 . 0 has the right extensions , \ n \ you may be able to modify this program to make it run . \ n " ; %! exit 1 ; end ; init ( ) ; glutDisplayFunc ~ display ; glutReshapeFunc ~ reshape ; glutMouseFunc ~ mouse ; glutKeyboardFunc ~ keyboard ; glutMainLoop ( ) ; ; ; |
let names bounded env = Env . fold ( fun n _ bounded -> S . add n bounded ) env bounded |
let rec fv_pat bounded acc p = match p . p_desc with | Ewildpat | Econstr0pat _ | Econstpat _ -> acc | Evarpat ( x ) -> if ( S . mem x acc ) || ( S . mem x bounded ) then acc else S . add x acc | Econstr1pat ( _ , pat_list ) | Etuplepat ( pat_list ) -> List . fold_left ( fv_pat bounded ) acc pat_list | Erecordpat ( label_pat_list ) -> List . fold_left ( fun acc ( _ , p ) -> fv_pat bounded acc p ) acc label_pat_list | Ealiaspat ( p , name ) -> let acc = fv_pat bounded acc p | Eorpat ( p1 , _ ) -> fv_pat bounded acc p1 | Etypeconstraintpat ( p , _ ) -> fv_pat bounded acc p |
let fv_block fv_local fv_body bounded acc { b_env = b_env ; b_locals = l_list ; b_body = body ; b_write = defnames } = let bounded = names bounded b_env in let bounded , acc = List . fold_left fv_local ( bounded , acc ) l_list in bounded , fv_body bounded acc body |
let fv_match_handler fv_body m_h_list bounded acc = List . fold_left ( fun acc { m_pat = pat ; m_body = b ; m_env = env } -> fv_body ( names bounded env ) acc b ) acc m_h_list |
let rec size acc { desc = desc } = match desc with | Sconst _ | Sglobal _ -> acc | Sname ( n ) -> S . add n acc | Sop ( _ , s1 , s2 ) -> size ( size acc s1 ) s2 |
let operator acc = function | Efby | Eunarypre | Eifthenelse | Etest | Eminusgreater | Eup | Einitial | Edisc | Ehorizon | Eaccess | Eupdate | Econcat | Eatomic -> acc | Eslice ( s1 , s2 ) -> size ( size acc s1 ) s2 |
let rec fv bounded ( last_acc , acc ) e = match e . e_desc with | Eop ( op , e_list ) -> let last_acc , acc = List . fold_left ( fv bounded ) ( last_acc , acc ) e_list in last_acc , operator acc op | Econstr1 ( _ , e_list ) | Etuple ( e_list ) -> List . fold_left ( fv bounded ) ( last_acc , acc ) e_list | Eapp ( _ , e , e_list ) -> List . fold_left ( fv bounded ) ( fv bounded ( last_acc , acc ) e ) e_list | Elocal ( n ) -> last_acc , if ( S . mem n acc ) || ( S . mem n bounded ) then acc else S . add n acc | Elast ( n ) -> ( if ( S . mem n last_acc ) || ( S . mem n bounded ) then last_acc else S . add n last_acc ) , acc | Erecord_access ( e , _ ) | Etypeconstraint ( e , _ ) -> fv bounded ( last_acc , acc ) e | Erecord ( f_e_list ) -> List . fold_left ( fun acc ( _ , e ) -> fv bounded acc e ) ( last_acc , acc ) f_e_list | Erecord_with ( e , f_e_list ) -> let last_acc , acc = fv bounded ( last_acc , acc ) e in List . fold_left ( fun acc ( _ , e ) -> fv bounded acc e ) ( last_acc , acc ) f_e_list | Elet ( local , e ) -> let bounded , acc = fv_local ( bounded , ( last_acc , acc ) ) local in fv bounded acc e | Eblock ( b , e ) -> let acc = fv_block_eq_list bounded ( last_acc , acc ) b in fv bounded acc e | Eseq ( e1 , e2 ) -> fv bounded ( fv bounded ( last_acc , acc ) e1 ) e2 | Econst _ | Econstr0 _ | Eglobal _ | Eperiod _ -> last_acc , acc | Epresent _ | Ematch _ -> assert false match desc with | EQeq ( _ , e ) | EQinit ( _ , e ) | EQpluseq ( _ , e ) -> | EQmatch ( _ , e , m_h_list ) -> fv_match_handler fv_block_eq_list m_h_list bounded | EQreset ( eq_list , r ) -> fv bounded ( fv_eq_list bounded ( last_acc , acc ) eq_list ) r | EQder ( _ , e , None , [ ] ) -> fv bounded ( last_acc , acc ) e | EQblock ( b ) -> fv_block_eq_list bounded ( last_acc , acc ) b | EQand ( eq_list ) | EQbefore ( eq_list ) -> fv_eq_list bounded ( last_acc , acc ) eq_list | EQforall { for_index = i_list ; for_init = init_list ; let index ( last_acc , acc ) { desc = desc } = match desc with | Einput ( _ , e ) -> fv bounded ( last_acc , acc ) e | Eindex ( _ , e1 , e2 ) -> | Eoutput _ -> last_acc , acc in let init ( bounded , last_acc , acc ) { desc = desc } = match desc with | Einit_last ( x , e ) -> let last_acc , acc = List . fold_left index ( last_acc , acc ) i_list in let bounded , last_acc , acc = List . fold_left init ( bounded , last_acc , acc ) init_list in fv_block_eq_list bounded ( last_acc , acc ) b_eq_list | EQder _ | EQemit _ | EQpresent _ | EQautomaton _ | EQnext _ -> assert false let bounded = names bounded l_env in let acc = List . fold_left ( fv_eq bounded ) acc eq_list in ( bounded , acc ) let _ , acc = fv_block fv_local fv_eq_list bounded acc b in acc |
let fve acc e = let acc_last , acc = fv S . empty ( S . empty , acc ) e in S . union acc_last acc |
let empty_vcf = " ## fileformat = VCFv4 . 1 ## source = VarScan2 ## FORMAT =< ID = GT , Number = 1 , Type = String , Description " =\ Genotype " \> # CHROM \ tPOS \ tID \ tREF \ tALT \ tQUAL \ tFILTER \ tINFO \ tFORMAT \ tNORMAL \ tTUMOR " |
let somatic_on_region ~ run_with ? adjust_mapq ~ normal ~ tumor ~ result_prefix region = let open KEDSL in let name = Filename . basename result_prefix in let result_file suffix = result_prefix ^ suffix in let varscan_tool = Machine . get_tool run_with Machine . Tool . Default . varscan in let snp_output = result_file " - snp . vcf " in let indel_output = result_file " - indel . vcf " in let normal_pileup = Samtools . mpileup ~ run_with ~ region ? adjust_mapq normal in let tumor_pileup = Samtools . mpileup ~ run_with ~ region ? adjust_mapq tumor in let host = Machine . as_host run_with in let tags = [ Target_tags . variant_caller ; " varscan " ] in let varscan_somatic = let name = " somatic " - ^ name in let make = let big_one_liner = " if [ - s " ^ normal_pileup # product # path ^ " ] && [ - s " ^ tumor_pileup # product # path ^ " ] ; then " ^ sprintf " java - jar $ VARSCAN_JAR somatic % s % s \ -- output - snp % s \ -- output - indel % s \ -- output - vcf 1 ; " normal_pileup # product # path tumor_pileup # product # path snp_output indel_output ^ " else " ^ " echo ' " ^ empty_vcf ^ " ' > " ^ snp_output ^ " ; " ^ " echo ' " ^ empty_vcf ^ " ' > " ^ indel_output ^ " ; " ^ " fi " in Program . ( Machine . Tool . init varscan_tool && sh big_one_liner ) |> Machine . run_big_program run_with ~ name ~ processors : 1 ~ self_ids [ " : varscan " ; " somatic " ] in workflow_node ~ name ~ make ( single_file snp_output ~ host ) ~ tags ~ edges [ : depends_on ( Machine . Tool . ensure varscan_tool ) ; depends_on normal_pileup ; depends_on tumor_pileup ; on_failure_activate ( Remove . file ~ run_with snp_output ) ; on_failure_activate ( Remove . file ~ run_with indel_output ) ; ] in let snp_filtered = result_file " - snpfiltered . vcf " in let indel_filtered = result_file " - indelfiltered . vcf " in let varscan_filter = let name = " filter " - ^ name in let make = Program . ( Machine . Tool . init varscan_tool && shf " java - jar $ VARSCAN_JAR somaticFilter % s \ -- indel - file % s \ -- output - file % s " snp_output indel_output snp_filtered && shf " java - jar $ VARSCAN_JAR processSomatic % s " snp_filtered && shf " java - jar $ VARSCAN_JAR processSomatic % s " indel_output ) |> Machine . run_big_program run_with ~ name ~ processors : 1 ~ self_ids [ " : varscan " ; " somaticfilter " ] in workflow_node ~ name ~ make ~ tags ( vcf_file snp_filtered ~ reference_build : normal # product # reference_build ~ host ) ~ edges [ : depends_on varscan_somatic ; on_failure_activate ( Remove . file ~ run_with snp_filtered ) ; on_failure_activate ( Remove . file ~ run_with indel_filtered ) ; ] in varscan_filter |
let somatic_map_reduce ( ? more_edges = [ ] ) ~ run_with ? adjust_mapq ~ normal ~ tumor ~ result_prefix ( ) = let run_on_region region = let result_prefix = result_prefix ^ " " - ^ Region . to_filename region in somatic_on_region ~ run_with ? adjust_mapq ~ normal ~ tumor ~ result_prefix region in let reference = Machine . get_reference_genome run_with normal # product # reference_build in let targets = List . map ( Reference_genome . major_contigs reference ) ~ f : run_on_region in let final_vcf = result_prefix ^ " - merged . vcf " in Vcftools . vcf_concat ~ run_with targets ~ final_vcf ~ more_edges |
type t = private [ > ] ; ; |
type u = private [ > ] ~ [ t ] ; ; |
type v = [ t | u ] ; ; |
let f x = ( x : t :> v ) ; ; |
module Mix ( X : sig type t = private [ > ] end ) ( Y : sig type t = private [ > ] end ) = struct type t = [ X . t | Y . t ] end ; ; |
module Mix ( X : sig type t = private [ > ` A of int ] end ) ( Y : sig type t = private [ > ` A of bool ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] end ; ; |
module Mix ( X : sig type t = private [ > ` A of int ] end ) ( Y : sig type t = private [ > ` A of int ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] end ; ; |
module Mix ( X : sig type t = private [ > ` A of int ] end ) ( Y : sig type t = private [ > ` B of bool ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] end ; ; |
type ' a t = private [ > ` L of ' a ] ~ [ ` L ] ; ; |
module Mix ( X : sig type t = private [ > ` A of int ] ~ [ ` B ] end ) ( Y : sig type t = private [ > ` B of bool ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] let is_t = function # t -> true | _ -> false end ; ; |
module Mix ( X : sig type t = private [ > ` A of int ] ~ [ ` B ] end ) ( Y : sig type t = private [ > ` B of bool ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] let which = function # X . t -> ` X | # Y . t -> ` Y end ; ; |
module Mix ( I : sig type t = private [ > ] ~ [ ` A ; ` B ] end ) ( X : sig type t = private [ > I . t | ` A of int ] ~ [ ` B ] end ) ( Y : sig type t = private [ > I . t | ` B of bool ] ~ [ X . t ] end ) = struct type t = [ X . t | Y . t ] let which = function # X . t -> ` X | # Y . t -> ` Y end ; ; |
module M = Mix ( struct type t = [ ` C of char ] end ) ( struct type t = [ ` A of int | ` C of char ] end ) ( struct type t = [ ` B of bool | ` C of char ] end ) ; ; |
module M = Mix ( struct type t = [ ` B of bool ] end ) ( struct type t = [ ` A of int | ` B of bool ] end ) ( struct type t = [ ` B of bool | ` C of char ] end ) ; ; |
module M1 = struct type t = [ ` A of int | ` C of char ] end |
module M2 = struct type t = [ ` B of bool | ` C of char ] end |
module I = struct type t = [ ` C of char ] end |
module M = Mix ( I ) ( M1 ) ( M2 ) ; ; |
let c = ( ` C ' c ' : M . t ) ; ; |
module M ( X : sig type t = private [ > ` A ] end ) = struct let f ( # X . t as x ) = x end ; ; |
type t = private [ > ` A ] ~ [ ` B ] ; ; |
module M : sig type t = private [ > ` A of int | ` B ] ~ [ ` C ] end = struct type t = [ ` A of int | ` B | ` D of bool ] end ; ; |
let f = function ( ` C | # M . t ) -> 1 + 1 ; ; |
let f = function ( ` A _ | ` B # M . t ) -> 1 + 1 ; ; |
module Mix ( X : sig type t = private [ > ] val show : t -> string end ) ( Y : sig type t = private [ > ] ~ [ X . t ] val show : t -> string end ) = struct type t = [ X . t | Y . t ] let show : t -> string = function # X . t as x -> X . show x | # Y . t as y -> Y . show y end ; ; |
module EStr = struct type t = [ ` Str of string ] let show ( ` Str s ) = s end |
module EInt = struct type t = [ ` Int of int ] let show ( ` Int i ) = string_of_int i end |
module type T = sig type t = private [ > ] val show : t -> string end |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.