diff --git a/jscomp/others/.depend b/jscomp/others/.depend index 2863cfe77d..79615d75f3 100644 --- a/jscomp/others/.depend +++ b/jscomp/others/.depend @@ -17,9 +17,9 @@ js_console.cmj : js_result.cmj : js_result.cmi js_mapperRt.cmj : js_mapperRt.cmi bs_Array.cmj : js_math.cmj bs_Array.cmi -bs_internalAVLset.cmj : bs_SortArray.cmj bs_Dict.cmj bs_Array.cmj \ +bs_internalAVLset.cmj : bs_SortArray.cmj bs_Id.cmj bs_Array.cmj \ bs_internalAVLset.cmi -bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Dict.cmj bs_Array.cmj \ +bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Id.cmj bs_Array.cmj \ bs_internalAVLtree.cmi bs_List.cmj : bs_Array.cmj bs_List.cmi bs_SortArray.cmj : bs_SortArrayString.cmj bs_SortArrayInt.cmj bs_Array.cmj \ @@ -32,22 +32,20 @@ bs_internalSetBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj \ bs_internalSetBuckets.cmi bs_internalBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj \ bs_internalBuckets.cmi -bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \ - bs_HashMapString.cmj bs_HashMapInt.cmj bs_Dict.cmj bs_Array.cmj \ - bs_HashMap.cmi +bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj bs_Id.cmj \ + bs_HashMapString.cmj bs_HashMapInt.cmj bs_Array.cmj bs_HashMap.cmi bs_HashSet.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \ - bs_HashSetString.cmj bs_HashSetInt.cmj bs_Dict.cmj bs_Array.cmj \ + bs_Id.cmj bs_HashSetString.cmj bs_HashSetInt.cmj bs_Array.cmj \ bs_HashSet.cmi bs_HashSetString.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \ bs_Array.cmj bs_HashSetString.cmi bs_HashSetInt.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \ bs_Array.cmj bs_HashSetInt.cmi -bs_Dict.cmj : bs_Dict.cmi -bs_MapDict.cmj : bs_internalAVLtree.cmj bs_Dict.cmj bs_Array.cmj \ +bs_Id.cmj : bs_Id.cmi +bs_MapDict.cmj : bs_internalAVLtree.cmj bs_Id.cmj bs_Array.cmj \ bs_MapDict.cmi -bs_SetDict.cmj : bs_internalAVLset.cmj bs_Dict.cmj bs_Array.cmj \ - bs_SetDict.cmi -bs_Map.cmj : bs_MapString.cmj bs_MapInt.cmj bs_MapDict.cmj bs_Dict.cmj \ +bs_SetDict.cmj : bs_internalAVLset.cmj bs_Id.cmj bs_Array.cmj bs_SetDict.cmi +bs_Map.cmj : bs_MapString.cmj bs_MapInt.cmj bs_MapDict.cmj bs_Id.cmj \ bs_Array.cmj bs_Map.cmi bs_internalMapInt.cmj : bs_internalAVLtree.cmj bs_SortArray.cmj bs_Array.cmj bs_internalMapString.cmj : bs_internalAVLtree.cmj bs_SortArray.cmj \ @@ -56,17 +54,17 @@ bs_MapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \ bs_Array.cmj bs_MapString.cmi bs_MapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \ bs_MapInt.cmi -bs_Set.cmj : bs_SetString.cmj bs_SetInt.cmj bs_SetDict.cmj bs_Dict.cmj \ +bs_Set.cmj : bs_SetString.cmj bs_SetInt.cmj bs_SetDict.cmj bs_Id.cmj \ bs_Array.cmj bs_Set.cmi bs_MutableSet.cmj : bs_internalAVLset.cmj bs_SortArray.cmj \ - bs_MutableSetString.cmj bs_MutableSetInt.cmj bs_Dict.cmj bs_Array.cmj \ + bs_MutableSetString.cmj bs_MutableSetInt.cmj bs_Id.cmj bs_Array.cmj \ bs_MutableSet.cmi bs_MutableSetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \ bs_SortArrayInt.cmj bs_Array.cmj bs_MutableSetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \ bs_SortArrayString.cmj bs_Array.cmj bs_MutableSetString.cmi bs_MutableMap.cmj : bs_internalAVLtree.cmj bs_MutableMapString.cmj \ - bs_MutableMapInt.cmj bs_Dict.cmj bs_Array.cmj bs_MutableMap.cmi + bs_MutableMapInt.cmj bs_Id.cmj bs_Array.cmj bs_MutableMap.cmi bs_MutableMapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj \ bs_Array.cmj bs_MutableMapInt.cmi bs_MutableMapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \ @@ -104,8 +102,8 @@ js_option.cmi : js_result.cmi : js_mapperRt.cmi : bs_Array.cmi : -bs_internalAVLset.cmi : bs_Dict.cmi -bs_internalAVLtree.cmi : bs_Dict.cmi +bs_internalAVLset.cmi : bs_Id.cmi +bs_internalAVLtree.cmi : bs_Id.cmi bs_List.cmi : bs_SortArray.cmi : bs_SortArrayString.cmi bs_SortArrayInt.cmi bs_SortArrayInt.cmi : @@ -114,20 +112,20 @@ bs_Range.cmi : bs_internalBucketsType.cmi : bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi bs_internalBuckets.cmi : bs_internalBucketsType.cmi -bs_HashMap.cmi : bs_HashMapString.cmi bs_HashMapInt.cmi bs_Dict.cmi -bs_HashSet.cmi : bs_HashSetString.cmi bs_HashSetInt.cmi bs_Dict.cmi +bs_HashMap.cmi : bs_Id.cmi bs_HashMapString.cmi bs_HashMapInt.cmi +bs_HashSet.cmi : bs_Id.cmi bs_HashSetString.cmi bs_HashSetInt.cmi bs_HashSetString.cmi : bs_HashSetInt.cmi : -bs_Dict.cmi : -bs_MapDict.cmi : bs_Dict.cmi -bs_SetDict.cmi : bs_Dict.cmi -bs_Map.cmi : bs_MapString.cmi bs_MapInt.cmi bs_MapDict.cmi bs_Dict.cmi +bs_Id.cmi : +bs_MapDict.cmi : bs_Id.cmi +bs_SetDict.cmi : bs_Id.cmi +bs_Map.cmi : bs_MapString.cmi bs_MapInt.cmi bs_MapDict.cmi bs_Id.cmi bs_MapString.cmi : bs_MapInt.cmi : -bs_Set.cmi : bs_SetString.cmi bs_SetInt.cmi bs_SetDict.cmi bs_Dict.cmi -bs_MutableSet.cmi : bs_MutableSetString.cmi bs_MutableSetInt.cmj bs_Dict.cmi +bs_Set.cmi : bs_SetString.cmi bs_SetInt.cmi bs_SetDict.cmi bs_Id.cmi +bs_MutableSet.cmi : bs_MutableSetString.cmi bs_MutableSetInt.cmj bs_Id.cmi bs_MutableSetString.cmi : -bs_MutableMap.cmi : bs_MutableMapString.cmi bs_MutableMapInt.cmi bs_Dict.cmi +bs_MutableMap.cmi : bs_MutableMapString.cmi bs_MutableMapInt.cmi bs_Id.cmi bs_MutableMapInt.cmi : bs_MutableMapString.cmi : bs_SetInt.cmi : diff --git a/jscomp/others/Makefile b/jscomp/others/Makefile index d055cdeec7..5041306530 100644 --- a/jscomp/others/Makefile +++ b/jscomp/others/Makefile @@ -26,7 +26,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string bs_HashSet\ bs_HashSetString\ bs_HashSetInt\ - bs_Dict\ + bs_Id\ bs_MapDict\ bs_SetDict\ bs_Map\ diff --git a/jscomp/others/bs.ml b/jscomp/others/bs.ml index c89a4f60ee..3f1ef7cd08 100644 --- a/jscomp/others/bs.ml +++ b/jscomp/others/bs.ml @@ -25,7 +25,7 @@ (** A stdlib shipped with BuckleScript - This stdlib is still in beta status, but we encourage you to try it out and + This stdlib is still in {i beta} status, but we encourage you to try it out and provide feedback. {b Motivation } @@ -70,29 +70,30 @@ {[ type t = int * int module I0 = - (val Bs.Dict.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) -> + (val Bs.Id.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) -> match compare a0 b0 with | 0 -> compare a1 b1 | c -> c )) - let s0 = Bs.Set.make (module I0) + let s0 = Bs.Set.make ~id:(module I0) module I1 = - (val Bs.Dict.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) -> + (val Bs.Id.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) -> match compare a1 b1 with | 0 -> compare a0 b0 | c -> c )) - let s1 = Bs.Set.make (module I1) + let s1 = Bs.Set.make ~id:(module I1) ]} Here the compiler would infer [s0] and [s1] having different type so that it would not mix. {[ - val s0 : Bs.Set.t ((int * int), I0.id) - val s1 : Bs.Set.t ((int * int), I1.id) + val s0 : Bs.Set.t ((int * int), I0.identity) + val s1 : Bs.Set.t ((int * int), I1.identity) ]} + [I0.identity] and [I1.identity] are not the same using our encoding scheme. {b Collection Hierachy} @@ -115,7 +116,7 @@ *) -(** {!Bs.Dict} +(** {!Bs.Id} Provide utiliites to create identified comparators or hashes for data structures used below. @@ -124,7 +125,7 @@ functions so that different data structures with slightly different comparison functions won't mix *) -module Dict = Bs_Dict +module Id = Bs_Id (** {!Bs.Array} diff --git a/jscomp/others/bs_Array.ml b/jscomp/others/bs_Array.ml index 770f4d7f70..e15235a2f1 100644 --- a/jscomp/others/bs_Array.ml +++ b/jscomp/others/bs_Array.ml @@ -108,7 +108,29 @@ let makeByAndShuffleU l f = let makeByAndShuffle l f = makeByAndShuffleU l (fun[@bs] a -> f a) +let range start finish = + let cut = finish - start in + if cut < 0 then [||] + else + let arr = makeUninitializedUnsafe (cut + 1 ) in + for i = 0 to cut do + setUnsafe arr i (start + i) + done; + arr +let rangeBy start finish ~step = + let cut = finish - start in + if cut < 0 || step <=0 then + [||] + else + let nb = cut/step + 1 in + let arr = makeUninitializedUnsafe nb in + let cur = ref start in + for i = 0 to nb - 1 do + setUnsafe arr i !cur; + cur := !cur + step ; + done; + arr let zip xs ys = let lenx, leny = length xs, length ys in diff --git a/jscomp/others/bs_Array.mli b/jscomp/others/bs_Array.mli index 09b2e778f4..89b057e309 100644 --- a/jscomp/others/bs_Array.mli +++ b/jscomp/others/bs_Array.mli @@ -86,6 +86,31 @@ val make: int -> 'a -> 'a array @return an empty array when [n] is negative. *) +val range: int -> int -> int array +(** [range start finish] create an inclusive array + @example {[ + range 0 3 = [|0;1;2;3|];; + range 3 0 = [||] ;; + range 3 3 = [|3|];; + ]} +*) +val rangeBy: int -> int -> step:int -> int array +(** [rangeBy start finish ~step] + + @return empty array when step is 0 or negative + it also return empty array when [start > finish] + + @example {[ + rangeBy 0 10 ~step:3 = [|0;3;6;9|];; + rangeBy 0 12 ~step:3 = [|0;3;6;9;12|];; + rangeBy 33 0 ~step:1 = [||];; + rangeBy 33 0 ~step:(-1) = [||];; + rangeBy 3 12 ~step:(-1) = [||];; + rangeBy 3 3 ~step:0 = [||] ;; + rangeBy 3 3 ~step:(1) = [|3|] ;; + ]} +*) + val makeByU: int -> (int -> 'a [@bs]) -> 'a array val makeBy: int -> (int -> 'a ) -> 'a array (** [makeBy n f] diff --git a/jscomp/others/bs_Bag.ml b/jscomp/others/bs_Bag.ml deleted file mode 100644 index c7d97a6127..0000000000 --- a/jscomp/others/bs_Bag.ml +++ /dev/null @@ -1,36 +0,0 @@ -(* Copyright (C) 2017 Authors of BuckleScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type (+ 'k, + 'v) bag = { - dict : 'k ; - data : 'v -} [@@bs.deriving abstract] - -(* without variance annotation - - {[ - let m = N.empty (module N) - ]} - will not be allowed if m is polymoprhic -*) diff --git a/jscomp/others/bs_BagM.ml b/jscomp/others/bs_BagM.ml deleted file mode 100644 index 24511b8acc..0000000000 --- a/jscomp/others/bs_BagM.ml +++ /dev/null @@ -1,6 +0,0 @@ - - -type (+ 'k, 'v ) bag = { - dict : 'k; - mutable data : 'v; -} [@@bs.deriving abstract] \ No newline at end of file diff --git a/jscomp/others/bs_HashMap.ml b/jscomp/others/bs_HashMap.ml index 499fbef763..761d9f58f8 100644 --- a/jscomp/others/bs_HashMap.ml +++ b/jscomp/others/bs_HashMap.ml @@ -17,9 +17,9 @@ module C = Bs_internalBucketsType module A = Bs_Array -type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq -type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable +type ('a, 'id) eq = ('a, 'id) Bs_Id.eq +type ('a, 'id) hash = ('a, 'id) Bs_Id.hash +type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable type ('a,'b,'id) t = ( ('a, 'id) hash, ('a, 'id) eq, 'a, 'b) N.t @@ -110,8 +110,8 @@ let set0 h key value ~eq ~hash = *) let set h key value = set0 h key value - ~eq:(Bs_Dict.getEqInternal (C.eq h)) - ~hash:(Bs_Dict.getHashInternal (C.hash h)) + ~eq:(Bs_Id.getEqInternal (C.eq h)) + ~hash:(Bs_Id.getHashInternal (C.hash h)) let rec removeInBucket h h_buckets i key prec bucket ~eq = match C.toOpt bucket with @@ -129,12 +129,12 @@ let rec removeInBucket h h_buckets i key prec bucket ~eq = let remove h key = let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let i = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = A.getUnsafe h_buckets i in match C.toOpt bucket with | None -> () | Some cell -> - let eq = (Bs_Dict.getEqInternal (C.eq h)) in + let eq = (Bs_Id.getEqInternal (C.eq h)) in if eq (N.key cell ) key [@bs] then begin A.setUnsafe h_buckets i (N.next cell); @@ -154,11 +154,11 @@ let rec getAux ~eq key buckets = let get h key = let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let nid = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in match C.toOpt @@ A.getUnsafe h_buckets nid with | None -> None | Some cell1 -> - let eq = Bs_Dict.getEqInternal (C.eq h) in + let eq = Bs_Id.getEqInternal (C.eq h) in if eq key (N.key cell1) [@bs] then Some (N.value cell1) else @@ -185,12 +185,12 @@ let rec memInBucket key cell ~eq = let has h key = let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let nid = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = A.getUnsafe h_buckets nid in match C.toOpt bucket with | None -> false | Some bucket -> - memInBucket ~eq:(Bs_Dict.getEqInternal (C.eq h)) key bucket + memInBucket ~eq:(Bs_Id.getEqInternal (C.eq h)) key bucket @@ -205,7 +205,7 @@ let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = let hash, eq = M.hash, M.eq in let len = A.length arr in let v = C.make ~hash ~eq len in - let eq, hash = Bs_Dict.getEqInternal eq, Bs_Dict.getHashInternal hash in + let eq, hash = Bs_Id.getEqInternal eq, Bs_Id.getHashInternal hash in for i = 0 to len - 1 do let key,value = (A.getUnsafe arr i) in set0 ~eq ~hash v key value @@ -213,7 +213,7 @@ let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = v let mergeMany h arr = - let hash, eq = Bs_Dict.getHashInternal ( C.hash h) , Bs_Dict.getEqInternal (C.eq h) in + let hash, eq = Bs_Id.getHashInternal ( C.hash h) , Bs_Id.getEqInternal (C.eq h) in let len = A.length arr in for i = 0 to len - 1 do let key,value = (A.getUnsafe arr i) in diff --git a/jscomp/others/bs_HashMap.mli b/jscomp/others/bs_HashMap.mli index 606d30cc14..ea3f913a7d 100644 --- a/jscomp/others/bs_HashMap.mli +++ b/jscomp/others/bs_HashMap.mli @@ -28,7 +28,7 @@ type ('key,'value,'id) t (** The type of hash tables from type ['key] to type ['value]. *) -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable +type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable val make: int -> dict:('key, 'id) dict -> ('key,'value,'id) t diff --git a/jscomp/others/bs_HashSet.ml b/jscomp/others/bs_HashSet.ml index a5712a4a97..3716b4fb16 100644 --- a/jscomp/others/bs_HashSet.ml +++ b/jscomp/others/bs_HashSet.ml @@ -31,9 +31,9 @@ module N = Bs_internalSetBuckets module C = Bs_internalBucketsType module A = Bs_Array -type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq -type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable +type ('a, 'id) eq = ('a, 'id) Bs_Id.eq +type ('a, 'id) hash = ('a, 'id) Bs_Id.hash +type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable type ('a,'id) t = ( ('a, 'id) hash, ('a, 'id) eq, 'a) N.t @@ -43,7 +43,7 @@ let rec copyBucket ~hash ~h_buckets ~ndata_tail old_bucket = match C.toOpt old_bucket with | None -> () | Some cell -> - let nidx = (Bs_Dict.getHashInternal hash) (N.key cell) [@bs] land (A.length h_buckets - 1) in + let nidx = (Bs_Id.getHashInternal hash) (N.key cell) [@bs] land (A.length h_buckets - 1) in let v = C.return cell in begin match C.toOpt (A.getUnsafe ndata_tail nidx) with | None -> @@ -77,7 +77,7 @@ let tryDoubleResize ~hash h = let rec removeBucket ~eq h h_buckets i key prec cell = let cell_next = N.next cell in - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] + if (Bs_Id.getEqInternal eq) (N.key cell) key [@bs] then begin N.nextSet prec cell_next; @@ -93,13 +93,13 @@ let rec removeBucket ~eq h h_buckets i key prec cell = let remove h key = let eq = C.eq h in let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let i = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let l = A.getUnsafe h_buckets i in match C.toOpt l with | None -> () | Some cell -> let next_cell = N.next cell in - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] then + if (Bs_Id.getEqInternal eq) (N.key cell) key [@bs] then begin C.sizeSet h (C.size h - 1) ; A.setUnsafe h_buckets i next_cell @@ -113,7 +113,7 @@ let remove h key = let rec addBucket h key cell ~eq = - if not ((Bs_Dict.getEqInternal eq) (N.key cell) key [@bs]) then + if not ((Bs_Id.getEqInternal eq) (N.key cell) key [@bs]) then let n = N.next cell in match C.toOpt n with | None -> @@ -124,7 +124,7 @@ let rec addBucket h key cell ~eq = let add0 h key ~hash ~eq = let h_buckets = C.buckets h in let buckets_len = A.length h_buckets in - let i = (Bs_Dict.getHashInternal hash) key [@bs] land (buckets_len - 1) in + let i = (Bs_Id.getHashInternal hash) key [@bs] land (buckets_len - 1) in let l = A.getUnsafe h_buckets i in (match C.toOpt l with | None -> @@ -139,7 +139,7 @@ let add h key = add0 ~hash:(C.hash h) ~eq:(C.eq h) h key let rec memInBucket ~eq key cell = - (Bs_Dict.getEqInternal eq) + (Bs_Id.getEqInternal eq) (N.key cell) key [@bs] || (match C.toOpt (N.next cell) with | None -> false @@ -150,7 +150,7 @@ let rec memInBucket ~eq key cell = let has h key = let eq, h_buckets = C.eq h, C.buckets h in - let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let nid = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = A.getUnsafe h_buckets nid in match C.toOpt bucket with | None -> false diff --git a/jscomp/others/bs_HashSet.mli b/jscomp/others/bs_HashSet.mli index c042eaee1f..bbb92b5b55 100644 --- a/jscomp/others/bs_HashSet.mli +++ b/jscomp/others/bs_HashSet.mli @@ -34,7 +34,7 @@ type ('a, 'id) t (** The type of hash tables from type ['a] to type ['b]. *) -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable +type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable val make: int -> dict:('a,'id) dict -> ('a, 'id) t val clear: ('a, 'id) t -> unit diff --git a/jscomp/others/bs_Dict.ml b/jscomp/others/bs_Id.ml similarity index 91% rename from jscomp/others/bs_Dict.ml rename to jscomp/others/bs_Id.ml index dffde48cb6..993fbc3cae 100644 --- a/jscomp/others/bs_Dict.ml +++ b/jscomp/others/bs_Id.ml @@ -34,13 +34,13 @@ external getCmpInternal : ('a,'id) cmp -> ('a -> 'a -> int [@bs]) = "%identity" module type Comparable = sig - type id + type identity type t - val cmp: (t, id) cmp + val cmp: (t, identity) cmp end type ('key, 'id) comparable = - (module Comparable with type t = 'key and type id = 'id) + (module Comparable with type t = 'key and type identity = 'id) module MakeComparable (M : sig @@ -48,7 +48,7 @@ module MakeComparable (M : sig val cmp: t -> t -> int [@bs] end) = struct - type id + type identity type t = M.t let cmp = M.cmp end @@ -68,13 +68,13 @@ let comparable ~cmp = comparableU ~cmp:(fun[@bs] a b -> cmp a b) module type Hashable = sig - type id + type identity type t - val hash: (t,id) hash - val eq: (t,id) eq + val hash: (t,identity) hash + val eq: (t,identity) eq end -type ('key, 'id) hashable = (module Hashable with type t = 'key and type id = 'id) +type ('key, 'id) hashable = (module Hashable with type t = 'key and type identity = 'id) module MakeHashable (M : sig type t @@ -82,7 +82,7 @@ module MakeHashable (M : sig val eq : t -> t -> bool [@bs] end) = struct - type id + type identity type t = M.t let hash = M.hash let eq = M.eq diff --git a/jscomp/others/bs_Dict.mli b/jscomp/others/bs_Id.mli similarity index 93% rename from jscomp/others/bs_Dict.mli rename to jscomp/others/bs_Id.mli index fbfb310ec4..66d0971228 100644 --- a/jscomp/others/bs_Dict.mli +++ b/jscomp/others/bs_Id.mli @@ -24,7 +24,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** {!Bs.Dict} +(** {!Bs.Id} Provide utiliites to create identified comparators or hashes for data structures used below. @@ -57,13 +57,13 @@ type ('a, 'id) cmp *) module type Comparable = sig - type id + type identity type t - val cmp: (t, id) cmp + val cmp: (t, identity) cmp end type ('key, 'id) comparable = - (module Comparable with type t = 'key and type id = 'id) + (module Comparable with type t = 'key and type identity = 'id) (** [('key, 'id) cmparable] is a module of functions, here it only includes [cmp]. Unlike normal functions, when created, it comes with a unique identity (guaranteed @@ -84,14 +84,14 @@ val comparable: (module Comparable with type t = 'a) module type Hashable = sig - type id + type identity type t - val hash: (t,id) hash - val eq: (t,id) eq + val hash: (t,identity) hash + val eq: (t,identity) eq end type ('key, 'id) hashable = - (module Hashable with type t = 'key and type id = 'id) + (module Hashable with type t = 'key and type identity = 'id) (** [('key, 'id) hashable] is a module of functions, here it only includes [hash], [eq]. Unlike normal functions, when created, it comes with a unique identity (guaranteed diff --git a/jscomp/others/bs_List.mli b/jscomp/others/bs_List.mli index 75a2774281..1a25c3bace 100644 --- a/jscomp/others/bs_List.mli +++ b/jscomp/others/bs_List.mli @@ -192,7 +192,7 @@ val mapReverse2U: 'a t -> 'b t -> ('a -> 'b -> 'c [@bs]) -> 'c t val mapReverse2: 'a t -> 'b t -> ('a -> 'b -> 'c) -> 'c t (** [mapReverse2 xs ys f] - equivalent to [reverse (map2 xs ys f)] + equivalent to [reverse (zipBy xs ys f)] @example {[ mapReverse2 [1;2;3] [1;2] (+) = [4;2] diff --git a/jscomp/others/bs_Map.ml b/jscomp/others/bs_Map.ml index 2a626cab96..1b01a321d0 100644 --- a/jscomp/others/bs_Map.ml +++ b/jscomp/others/bs_Map.ml @@ -9,8 +9,8 @@ (* under the terms of the GNU Library General Public License, with *) (* the special exception on linking described in file ../LICENSE. *) (* *) +(* Adapted by authors of BuckleScript without using functors *) (***********************************************************************) -(** Adapted by authors of BuckleScript without using functors *) (** specalized when key type is [int], more efficient than the gerneic type @@ -28,8 +28,8 @@ module Dict = Bs_MapDict module N = Bs_MapDict module A = Bs_Array -type ('key, 'id ) dict = ('key, 'id) Bs_Dict.comparable -type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id ) id = ('key, 'id) Bs_Id.comparable +type ('key, 'id ) cmp = ('key, 'id) Bs_Id.cmp module S = struct type ('k,'v,'id) t = { cmp: ('k,'id) cmp; @@ -40,8 +40,8 @@ end type ('k, 'v, 'id ) t = ('k, 'v, 'id) S.t -let ofArray (type k) (type id) data ~(dict : (k,id) dict) = - let module M = (val dict) in +let ofArray (type k) (type idx) data ~(id : (k,idx) id) = + let module M = (val id) in let cmp = M.cmp in S.t ~cmp ~data:(Dict.ofArray ~cmp data) @@ -81,8 +81,8 @@ let mergeU s1 s2 f = let merge s1 s2 f = mergeU s1 s2 (fun [@bs] a b c -> f a b c) -let make (type elt) (type id) ~(dict: (elt, id) dict) = - let module M = (val dict) in +let make (type elt) (type idx) ~(id: (elt, idx) id) = + let module M = (val id) in S.t ~cmp:M.cmp ~data:Dict.empty let isEmpty map = @@ -155,15 +155,15 @@ let cmp m1 m2 vcmp = cmpU m1 m2 (fun [@bs] a b -> vcmp a b) let getData = S.data -let getDict (type elt) (type id) (m : (elt,_,id) t) : (elt, id) dict = +let getId (type elt) (type identity) (m : (elt,_,identity) t) : (elt, identity) id = let module T = struct - type nonrec id = id + type nonrec identity = identity type nonrec t = elt let cmp = S.cmp m end in (module T ) -let packDictData (type elt) (type id) ~(dict : (elt, id) dict) ~data = - let module M = (val dict) in +let packIdData (type elt) (type idx) ~(id : (elt, idx) id) ~data = + let module M = (val id) in S.t ~cmp:M.cmp ~data diff --git a/jscomp/others/bs_Map.mli b/jscomp/others/bs_Map.mli index 07e2ac7b39..7dca36992a 100644 --- a/jscomp/others/bs_Map.mli +++ b/jscomp/others/bs_Map.mli @@ -9,11 +9,10 @@ (* under the terms of the GNU Library General Public License, with *) (* the special exception on linking described in file ../LICENSE. *) (* *) +(* Adapted by authors of BuckleScript without using functors *) (***********************************************************************) -(** Adapted by authors of BuckleScript without using functors *) - -(** specalized when key type is [int], more efficient +(** Specalized when key type is [int], more efficient than the gerneic type *) module Int = Bs_MapInt @@ -21,7 +20,7 @@ module Int = Bs_MapInt than the gerneic type *) module String = Bs_MapString -(** seprate function from data, a more verbsoe but slightly +(** Seprate function from data, a more verbsoe but slightly more efficient *) module Dict = Bs_MapDict @@ -29,32 +28,32 @@ module Dict = Bs_MapDict type ('k,'v,'id) t -type ('key, 'id ) dict = ('key, 'id) Bs_Dict.comparable +type ('key, 'id ) id = ('key, 'id) Bs_Id.comparable (** The data associated with a comparison function *) (* How we retain soundness: The only way to create a value of type [_ t] from scratch - is through [empty] which requires [_ Bs_Dict.t] - The only way to create [_ Bs_Dict.t] is using [Bs_Dict.Make] which + is through [empty] which requires [_ Bs_Id.t] + The only way to create [_ Bs_Id.t] is using [Bs_Id.Make] which will create a fresh type [id] per module Generic operations over tree without [cmp] are still exported (for efficient reasons) so that [data] does not need be boxed and unboxed. The soundness is guaranteed in two aspects: - When create a value of [_ t] it needs both [_ Bs_Dict.t] and [_ t0]. - [_ Bs_Dict.t] is an abstract type. Note [add0] requires [_ Bs_Dict.cmp] which - is also an abstract type which can only come from [_ Bs_Dict.t] + When create a value of [_ t] it needs both [_ Bs_Id.t] and [_ t0]. + [_ Bs_Id.t] is an abstract type. Note [add0] requires [_ Bs_Id.cmp] which + is also an abstract type which can only come from [_ Bs_Id.t] When destructing a value of [_ t], the ['id] parameter is threaded. *) -(* should not export [Bs_Dict.compare]. - should only export [Bs_Dict.t] or [Bs_Dict.cmp] instead *) +(* should not export [Bs_Id.compare]. + should only export [Bs_Id.t] or [Bs_Id.cmp] instead *) -val make: dict:('k, 'id) dict -> ('k, 'a, 'id) t +val make: id:('k, 'id) id -> ('k, 'a, 'id) t val isEmpty: _ t -> bool val has: ('k, 'a, 'id) t -> 'k -> bool @@ -112,7 +111,7 @@ val size: ('k, 'a, 'id) t -> int val toList: ('k, 'a, 'id) t -> ('k * 'a) list (** In increasing order*) val toArray: ('k, 'a, 'id) t -> ('k * 'a) array -val ofArray: ('k * 'a) array -> dict:('k,'id) dict -> ('k,'a,'id) t +val ofArray: ('k * 'a) array -> id:('k,'id) id -> ('k,'a,'id) t val keysToArray: ('k, 'a, 'id) t -> 'k array val valuesToArray: ('k, 'a, 'id) t -> 'a array val minKey: ('k, _, _) t -> 'k option @@ -213,9 +212,9 @@ val map: ('k, 'a, 'id) t -> ('a -> 'b) -> ('k ,'b,'id ) t val mapWithKeyU: ('k, 'a, 'id) t -> ('k -> 'a -> 'b [@bs]) -> ('k, 'b, 'id) t val mapWithKey: ('k, 'a, 'id) t -> ('k -> 'a -> 'b) -> ('k, 'b, 'id) t -val getDict: ('a, 'b, 'c) t -> ('a, 'c) dict +val getId: ('a, 'b, 'c) t -> ('a, 'c) id val getData: ('a, 'b, 'c) t -> ('a, 'b, 'c) Bs_MapDict.t -val packDictData: dict:('a, 'b) dict -> data:('a, 'c, 'b) Bs_MapDict.t -> ('a, 'c, 'b) t +val packIdData: id:('a, 'b) id -> data:('a, 'c, 'b) Bs_MapDict.t -> ('a, 'c, 'b) t diff --git a/jscomp/others/bs_MapDict.ml b/jscomp/others/bs_MapDict.ml index fb3449d465..e5a21c7634 100644 --- a/jscomp/others/bs_MapDict.ml +++ b/jscomp/others/bs_MapDict.ml @@ -27,7 +27,7 @@ module A = Bs_Array type ('key, 'a, 'id) t = ('key, 'a) N.t -type ('key, 'id) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) cmp = ('key, 'id) Bs_Id.cmp let empty = N.empty let ofArray = N.ofArray @@ -81,7 +81,7 @@ let rec set (t : _ t) newK newD ~cmp = | None -> N.singleton newK newD | Some n -> let k= N.key n in - let c = (Bs_Dict.getCmpInternal cmp) newK k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) newK k [@bs] in if c = 0 then N.return (N.updateValue n newD) else @@ -100,7 +100,7 @@ let rec updateU (t : _ t) newK f ~cmp : _ t = end | Some n -> let k= N.key n in - let c = (Bs_Dict.getCmpInternal cmp) newK k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) newK k [@bs] in if c = 0 then match f (Some (N.value n)) [@bs] with | None -> @@ -148,7 +148,7 @@ let update t newK f ~cmp = let rec removeAux0 n x ~cmp = let l,v,r = N.(left n, key n, right n ) in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then match N.toOpt l, N.toOpt r with | None, _ -> r @@ -189,7 +189,7 @@ let mergeMany h arr ~cmp = let rec splitAuxPivot n x pres ~cmp = let l,v,d,r = N.(left n , key n, value n, right n) in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then begin pres := Some d; (l, r) diff --git a/jscomp/others/bs_MapDict.mli b/jscomp/others/bs_MapDict.mli index 567d17029a..863c6a09ef 100644 --- a/jscomp/others/bs_MapDict.mli +++ b/jscomp/others/bs_MapDict.mli @@ -24,7 +24,7 @@ type ('key, 'value, 'id) t -type ('key, 'id) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) cmp = ('key, 'id) Bs_Id.cmp val empty: ('k, 'v, 'id) t diff --git a/jscomp/others/bs_MutableMap.ml b/jscomp/others/bs_MutableMap.ml index 628145df14..8e9bf3685e 100644 --- a/jscomp/others/bs_MutableMap.ml +++ b/jscomp/others/bs_MutableMap.ml @@ -30,8 +30,8 @@ module N = Bs_internalAVLtree module A = Bs_Array -type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable -type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) dict = ('key, 'id) Bs_Id.comparable +type ('key, 'id ) cmp = ('key, 'id) Bs_Id.cmp module S = struct type ('k, 'v, 'id) t = { @@ -44,7 +44,7 @@ type ('k, 'v, 'id) t = ('k, 'v, 'id) S.t let rec removeMutateAux nt x ~cmp = let k = N.key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then let l,r = N.(left nt, right nt) in match N.(toOpt l, toOpt r) with @@ -108,7 +108,7 @@ let rec updateDone t x f ~cmp = | None -> t) | Some nt -> let k = N.key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then begin match f (Some (N.value nt)) [@bs] with | None -> diff --git a/jscomp/others/bs_MutableMap.mli b/jscomp/others/bs_MutableMap.mli index 6017d23223..97b024449d 100644 --- a/jscomp/others/bs_MutableMap.mli +++ b/jscomp/others/bs_MutableMap.mli @@ -29,7 +29,7 @@ module String = Bs_MutableMapString type ('k,'v,'id) t -type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable +type ('key, 'id) dict = ('key, 'id) Bs_Id.comparable val make: dict:('k, 'id) dict -> ('k, 'a, 'id) t val clear: _ t -> unit diff --git a/jscomp/others/bs_MutableSet.ml b/jscomp/others/bs_MutableSet.ml index 0816d85561..3a8956e565 100644 --- a/jscomp/others/bs_MutableSet.ml +++ b/jscomp/others/bs_MutableSet.ml @@ -31,8 +31,8 @@ module A = Bs_Array module Sort = Bs_SortArray -type ('k, 'id) dict = ('k, 'id) Bs_Dict.comparable -type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp +type ('k, 'id) dict = ('k, 'id) Bs_Id.comparable +type ('key, 'id ) cmp = ('key, 'id) Bs_Id.cmp module S = struct type ('elt,'id) t = @@ -77,7 +77,7 @@ let remove d v = match N.toOpt oldRoot with | None -> () | Some oldRoot2 -> - let newRoot = remove0 ~cmp:(Bs_Dict.getCmpInternal (S.cmp d)) oldRoot2 v in + let newRoot = remove0 ~cmp:(Bs_Id.getCmpInternal (S.cmp d)) oldRoot2 v in if newRoot != oldRoot then S.dataSet d newRoot @@ -99,12 +99,12 @@ let removeMany d xs = let len = A.length xs in S.dataSet d (removeMany0 nt xs 0 len - ~cmp:(Bs_Dict.getCmpInternal (S.cmp d))) + ~cmp:(Bs_Id.getCmpInternal (S.cmp d))) let rec removeCheck0 nt x removed ~cmp= let k = N.key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then let () = removed := true in let l,r = N.(left nt, right nt) in @@ -167,7 +167,7 @@ let rec addCheck0 t x added ~cmp = let addCheck m e = let oldRoot = S.data m in let added = ref false in - let newRoot = addCheck0 ~cmp:(Bs_Dict.getCmpInternal (S.cmp m)) oldRoot e added in + let newRoot = addCheck0 ~cmp:(Bs_Id.getCmpInternal (S.cmp m)) oldRoot e added in if newRoot != oldRoot then S.dataSet m newRoot; !added @@ -253,7 +253,7 @@ let getExn d x = let split d key = let arr = N.toArray (S.data d) in let cmp = S.cmp d in - let i = Sort.binarySearchByU arr key (Bs_Dict.getCmpInternal cmp) in + let i = Sort.binarySearchByU arr key (Bs_Id.getCmpInternal cmp) in let len = A.length arr in if i < 0 then let next = - i -1 in @@ -301,7 +301,7 @@ let intersect a b : _ t = let tmp = A.makeUninitializedUnsafe totalSize in ignore @@ N.fillArray dataa0 0 tmp ; ignore @@ N.fillArray datab0 sizea tmp; - let p = Bs_Dict.getCmpInternal cmp in + let p = Bs_Id.getCmpInternal cmp in if (p (A.getUnsafe tmp (sizea - 1)) (A.getUnsafe tmp sizea) [@bs] < 0) || @@ -330,7 +330,7 @@ let diff a b : _ t = let tmp = A.makeUninitializedUnsafe totalSize in ignore @@ N.fillArray dataa0 0 tmp ; ignore @@ N.fillArray datab0 sizea tmp; - let p = Bs_Dict.getCmpInternal cmp in + let p = Bs_Id.getCmpInternal cmp in if (p (A.getUnsafe tmp (sizea - 1)) (A.getUnsafe tmp sizea) [@bs] < 0) || @@ -357,7 +357,7 @@ let union a b = let tmp = A.makeUninitializedUnsafe totalSize in ignore @@ N.fillArray dataa0 0 tmp ; ignore @@ N.fillArray datab0 sizea tmp ; - let p = (Bs_Dict.getCmpInternal cmp) in + let p = (Bs_Id.getCmpInternal cmp) in if p (A.getUnsafe tmp (sizea - 1)) (A.getUnsafe tmp sizea) [@bs] < 0 then diff --git a/jscomp/others/bs_MutableSet.mli b/jscomp/others/bs_MutableSet.mli index da22e3d85f..37602f555c 100644 --- a/jscomp/others/bs_MutableSet.mli +++ b/jscomp/others/bs_MutableSet.mli @@ -34,7 +34,7 @@ module String = Bs_MutableSetString type ('k,'id) t -type ('k, 'id) dict = ('k, 'id) Bs_Dict.comparable +type ('k, 'id) dict = ('k, 'id) Bs_Id.comparable val make: dict:('elt, 'id) dict -> ('elt, 'id) t diff --git a/jscomp/others/bs_Range.ml b/jscomp/others/bs_Range.ml index d773bb82de..31d7e3e1e4 100644 --- a/jscomp/others/bs_Range.ml +++ b/jscomp/others/bs_Range.ml @@ -40,12 +40,17 @@ let rec everyU s f p = let every s f p = everyU s f (fun [@bs] a -> p a) -let rec everyByU s f ~step p = +let rec everyByAux s f ~step p = if s > f then true else p s [@bs] && - (everyByU (s + step) f ~step p ) - + (everyByAux (s + step) f ~step p ) + +let everyByU s f ~step p = + if step > 0 then + everyByAux s f ~step p + else true (* return empty range [true]*) + let everyBy s f ~step p = everyByU s f ~step (fun [@bs] a -> p a) let rec someU s f p = @@ -57,11 +62,15 @@ let rec someU s f p = let some s f p = someU s f (fun[@bs] a -> p a) -let rec someByU s f ~step p = +let rec someByAux s f ~step p = if s > f then false else p s [@bs] || - (someByU (s + step) f ~step p ) + (someByAux (s + step) f ~step p ) +let someByU s f ~step p = + if step > 0 then + someByAux s f ~step p + else false (* return empty range, [false] *) let someBy s f ~step p = someByU s f ~step (fun[@bs] a -> p a) diff --git a/jscomp/others/bs_Range.mli b/jscomp/others/bs_Range.mli index 39fb443a5c..80a8d1fa72 100644 --- a/jscomp/others/bs_Range.mli +++ b/jscomp/others/bs_Range.mli @@ -23,17 +23,45 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(** A small module to provide a inclusive range operations [\[start, finsish\]], + it use a for-loop internally instead of creating an array +*) + val forEachU: int -> int -> (int -> unit [@bs]) -> unit val forEach: int -> int -> (int -> unit ) -> unit +(** [forEach start finish action] + equivalent to [Bs.Array.(forEach (range start finish) action)] +*) + val everyU: int -> int -> (int -> bool [@bs]) -> bool val every: int -> int -> (int -> bool ) -> bool +(** [every start finish p] + equivalent to [Bs.Array.(every (range start finish) p )] +*) + val everyByU: int -> int -> step:int -> (int -> bool [@bs]) -> bool val everyBy: int -> int -> step:int -> (int -> bool ) -> bool +(** [everyBy start finish ~step p] + {b See} {!Bs_Array.rangeBy} + + equivalent to [Bs.Array.(every (rangeBy start finish ~step) p)] +*) + val someU: int -> int -> (int -> bool [@bs]) -> bool val some: int -> int -> (int -> bool ) -> bool +(** [some start finish p] + + equivalent to [Bs.Array.(some (range start finish) p)] +*) val someByU: int -> int -> step:int -> (int -> bool [@bs]) -> bool val someBy: int -> int -> step:int -> (int -> bool ) -> bool +(** [someBy start finish ~step p] + + {b See} {!Bs_Array.rangeBy} + + equivalent to [Bs.Array.(some (rangeBy start finish ~step) p)] +*) diff --git a/jscomp/others/bs_Set.ml b/jscomp/others/bs_Set.ml index 3a5cf1a348..df61f53b6a 100644 --- a/jscomp/others/bs_Set.ml +++ b/jscomp/others/bs_Set.ml @@ -29,8 +29,8 @@ module Dict = Bs_SetDict module A = Bs_Array -type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable -type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) dict = ('key, 'id) Bs_Id.comparable +type ('key, 'id ) cmp = ('key, 'id) Bs_Id.cmp module S = struct type ('k,'id) t = { @@ -154,9 +154,9 @@ let ofSortedArrayUnsafe (type elt) (type id) xs ~(dict : (elt,id) dict ) = let getData = S.data -let getDict (type elt) (type id) (m : (elt,id) t) : (elt, id) dict = +let getDict (type elt) (type identity) (m : (elt,identity) t) : (elt, identity) dict = let module T = struct - type nonrec id = id + type nonrec identity = identity type nonrec t = elt let cmp = S.cmp m end in diff --git a/jscomp/others/bs_Set.mli b/jscomp/others/bs_Set.mli index d1f998e23f..ace6d6bca8 100644 --- a/jscomp/others/bs_Set.mli +++ b/jscomp/others/bs_Set.mli @@ -38,7 +38,7 @@ module Dict = Bs_SetDict type ('k,'id) t -type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable +type ('key, 'id) dict = ('key, 'id) Bs_Id.comparable val make: dict:('elt, 'id) dict -> ('elt, 'id) t diff --git a/jscomp/others/bs_SetDict.ml b/jscomp/others/bs_SetDict.ml index 701078d95d..86ac201678 100644 --- a/jscomp/others/bs_SetDict.ml +++ b/jscomp/others/bs_SetDict.ml @@ -27,7 +27,7 @@ module A = Bs_Array type ('k,'id) t = 'k N.t -type ('key, 'id) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) cmp = ('key, 'id) Bs_Id.cmp (* here we relies on reference transparence @@ -39,7 +39,7 @@ let rec add (t : _ t) x ~cmp : _ t = | None -> N.singleton x | Some nt -> let k = N.key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then t else let l,r = N.(left nt, right nt) in @@ -57,7 +57,7 @@ let rec remove (t : _ t) x ~cmp : _ t = None -> t | Some n -> let l,v,r = N.(left n , key n, right n) in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then match N.toOpt l, N.toOpt r with | (None, _) -> r @@ -96,7 +96,7 @@ let removeMany h arr ~cmp = let rec splitAuxNoPivot ~cmp (n : _ N.node) x : _ * _ = let l,v,r = N.(left n , key n, right n) in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then l,r else if c < 0 then @@ -116,7 +116,7 @@ let rec splitAuxNoPivot ~cmp (n : _ N.node) x : _ * _ = let rec splitAuxPivot ~cmp (n : _ N.node) x pres : _ * _ = let l,v,r = N.(left n , key n, right n) in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then begin pres := true; diff --git a/jscomp/others/bs_SetDict.mli b/jscomp/others/bs_SetDict.mli index 3dae907fe4..d5c9504633 100644 --- a/jscomp/others/bs_SetDict.mli +++ b/jscomp/others/bs_SetDict.mli @@ -24,7 +24,7 @@ type ('key, 'id) t -type ('key, 'id) cmp = ('key, 'id) Bs_Dict.cmp +type ('key, 'id) cmp = ('key, 'id) Bs_Id.cmp val empty: ('elt, 'id) t diff --git a/jscomp/others/bs_internalAVLset.ml b/jscomp/others/bs_internalAVLset.ml index 9fa82e3fa4..882fa74735 100644 --- a/jscomp/others/bs_internalAVLset.ml +++ b/jscomp/others/bs_internalAVLset.ml @@ -41,7 +41,7 @@ external return : 'a -> 'a Js.null = "%identity" external empty : 'a Js.null = "#null" external unsafeCoerce : 'a Js.null -> 'a = "%identity" -type ('a, 'b) cmp = ('a, 'b) Bs_Dict.cmp +type ('a, 'b) cmp = ('a, 'b) Bs_Id.cmp (* Sets are represented by balanced binary trees (the heights of the children differ by at most 2 *) @@ -474,14 +474,14 @@ let rec has (t: _ t) x ~cmp = | None -> false | Some n -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in c = 0 || has ~cmp (if c < 0 then left n else right n) x let rec compareAux e1 e2 ~cmp = match e1,e2 with | h1::t1, h2::t2 -> - let c = (Bs_Dict.getCmpInternal cmp) (key h1) (key h2) [@bs] in + let c = (Bs_Id.getCmpInternal cmp) (key h1) (key h2) [@bs] in if c = 0 then compareAux ~cmp (stackAllLeft (right h1) t1) @@ -507,7 +507,7 @@ let rec subset (s1 : _ t) (s2 : _ t) ~cmp = | Some t1 , Some t2 -> let l1,v1,r1 = (left t1, key t1, right t1) in let l2,v2,r2 = (left t2, key t2, right t2) in - let c = (Bs_Dict.getCmpInternal cmp) v1 v2 [@bs] in + let c = (Bs_Id.getCmpInternal cmp) v1 v2 [@bs] in if c = 0 then subset ~cmp l1 l2 && subset ~cmp r1 r2 else if c < 0 then @@ -522,7 +522,7 @@ let rec get (n : _ t) x ~cmp = None -> None | Some t (* Node(l, v, r, _) *) -> let v = key t in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then Some v else get ~cmp (if c < 0 then left t else right t) x @@ -532,7 +532,7 @@ let rec getUndefined (n : _ t) x ~cmp = None -> Js.Undefined.empty | Some t (* Node(l, v, r, _) *) -> let v = key t in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then Js.Undefined.return v else getUndefined ~cmp (if c < 0 then left t else right t) x @@ -541,7 +541,7 @@ let rec getExn (n : _ t) x ~cmp = None -> [%assert "getExn0"] | Some t (* Node(l, v, r, _) *) -> let v = key t in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then v else getExn ~cmp (if c < 0 then left t else right t) x @@ -621,7 +621,7 @@ let rec addMutate ~cmp (t : _ t) x = | None -> singleton x | Some nt -> let k = key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then t else let l, r = (left nt, right nt) in @@ -639,7 +639,7 @@ let ofArray (xs : _ array) ~cmp = if len = 0 then empty else let next = ref (S.strictlySortedLengthU xs - (fun [@bs] x y -> (Bs_Dict.getCmpInternal cmp) x y [@bs] < 0)) in + (fun [@bs] x y -> (Bs_Id.getCmpInternal cmp) x y [@bs] < 0)) in let result = ref (if !next >= 0 then ofSortedArrayAux xs 0 !next diff --git a/jscomp/others/bs_internalAVLset.mli b/jscomp/others/bs_internalAVLset.mli index 9503e3f1e0..a24f591586 100644 --- a/jscomp/others/bs_internalAVLset.mli +++ b/jscomp/others/bs_internalAVLset.mli @@ -37,7 +37,7 @@ and 'elt node = private { h : int } [@@bs.deriving abstract] -type ('a, 'b) cmp = ('a, 'b) Bs_Dict.cmp +type ('a, 'b) cmp = ('a, 'b) Bs_Id.cmp (* TODO: node is used in [subset] *) external toOpt : 'a Js.null -> 'a option = "#null_to_opt" external return : 'a -> 'a Js.null = "%identity" diff --git a/jscomp/others/bs_internalAVLtree.ml b/jscomp/others/bs_internalAVLtree.ml index a9fb7e3c79..22343c2a97 100644 --- a/jscomp/others/bs_internalAVLtree.ml +++ b/jscomp/others/bs_internalAVLtree.ml @@ -23,7 +23,7 @@ type ('k, 'v) node = { and ('key, 'a) t = ('key, 'a) node Js.null [@@bs.deriving abstract] -type ('k, 'id) cmp = ('k, 'id) Bs_Dict.cmp +type ('k, 'id) cmp = ('k, 'id) Bs_Id.cmp module A = Bs_Array module S = Bs_SortArray @@ -538,7 +538,7 @@ let ofSortedArrayUnsafe arr = let rec compareAux e1 e2 ~kcmp ~vcmp = match e1,e2 with | h1::t1, h2::t2 -> - let c = (Bs_Dict.getCmpInternal kcmp) (key h1) (key h2) [@bs] in + let c = (Bs_Id.getCmpInternal kcmp) (key h1) (key h2) [@bs] in if c = 0 then let cx = vcmp (value h1) (value h2) [@bs] in if cx = 0 then @@ -552,7 +552,7 @@ let rec compareAux e1 e2 ~kcmp ~vcmp = let rec eqAux e1 e2 ~kcmp ~veq = match e1,e2 with | h1::t1, h2::t2 -> - if (Bs_Dict.getCmpInternal kcmp) (key h1) (key h2) [@bs] = 0 && + if (Bs_Id.getCmpInternal kcmp) (key h1) (key h2) [@bs] = 0 && veq (value h1) (value h2) [@bs] then eqAux ~kcmp ~veq ( stackAllLeft (right h1) t1 ) (stackAllLeft (right h2) t2) @@ -582,7 +582,7 @@ let rec get n x ~cmp = None -> None | Some n (* Node(l, v, d, r, _) *) -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then Some (value n) else get ~cmp (if c < 0 then left n else right n) x @@ -591,7 +591,7 @@ let rec getUndefined n x ~cmp = | None -> Js.undefined | Some n -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then Js.Undefined.return (value n ) else getUndefined ~cmp (if c < 0 then left n else right n) x @@ -601,7 +601,7 @@ let rec getExn n x ~cmp = [%assert "getExn0"] | Some n (* Node(l, v, d, r, _)*) -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then value n else getExn ~cmp (if c < 0 then left n else right n) x @@ -611,7 +611,7 @@ let rec getWithDefault n x def ~cmp = def | Some n (* Node(l, v, d, r, _)*) -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in if c = 0 then value n else getWithDefault ~cmp (if c < 0 then left n else right n) x def @@ -621,7 +621,7 @@ let rec has n x ~cmp = false | Some n (* Node(l, v, d, r, _) *) -> let v = key n in - let c = (Bs_Dict.getCmpInternal cmp) x v [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x v [@bs] in c = 0 || has ~cmp (if c < 0 then left n else right n) x @@ -700,7 +700,7 @@ let rec updateMutate (t : _ t) x data ~cmp = | None -> singleton x data | Some nt -> let k = key nt in - let c = (Bs_Dict.getCmpInternal cmp) x k [@bs] in + let c = (Bs_Id.getCmpInternal cmp) x k [@bs] in if c = 0 then begin valueSet nt data; return nt @@ -722,7 +722,7 @@ let ofArray (xs : _ array) ~cmp = let next = ref (S.strictlySortedLengthU xs (fun[@bs] (x0,_) (y0,_) -> - (Bs_Dict.getCmpInternal cmp) x0 y0 [@bs] < 0 + (Bs_Id.getCmpInternal cmp) x0 y0 [@bs] < 0 )) in let result = ref ( diff --git a/jscomp/others/bs_internalAVLtree.mli b/jscomp/others/bs_internalAVLtree.mli index b43db0d6d6..5a22a53729 100644 --- a/jscomp/others/bs_internalAVLtree.mli +++ b/jscomp/others/bs_internalAVLtree.mli @@ -39,7 +39,7 @@ external toOpt : 'a Js.null -> 'a option = "#null_to_opt" external return : 'a -> 'a Js.null = "%identity" external empty : 'a Js.null = "#null" -type ('k, 'id) cmp = ('k, 'id) Bs_Dict.cmp +type ('k, 'id) cmp = ('k, 'id) Bs_Id.cmp val copy : ('k, 'v) t -> ('k, 'v) t val create : diff --git a/jscomp/test/bs.js b/jscomp/test/bs.js new file mode 100644 index 0000000000..2588aee4d0 --- /dev/null +++ b/jscomp/test/bs.js @@ -0,0 +1,43 @@ +'use strict'; + + +var Dict = 0; + +var $$Array = 0; + +var SortArray = 0; + +var MutableQueue = 0; + +var MutableStack = 0; + +var List = 0; + +var Range = 0; + +var $$Set = 0; + +var $$Map = 0; + +var MutableSet = 0; + +var MutableMap = 0; + +var HashSet = 0; + +var HashMap = 0; + +exports.Dict = Dict; +exports.$$Array = $$Array; +exports.SortArray = SortArray; +exports.MutableQueue = MutableQueue; +exports.MutableStack = MutableStack; +exports.List = List; +exports.Range = Range; +exports.$$Set = $$Set; +exports.$$Map = $$Map; +exports.MutableSet = MutableSet; +exports.MutableMap = MutableMap; +exports.HashSet = HashSet; +exports.HashMap = HashMap; +/* No side effect */ diff --git a/jscomp/test/bs_array_test.js b/jscomp/test/bs_array_test.js index 94115ab060..f70827e468 100644 --- a/jscomp/test/bs_array_test.js +++ b/jscomp/test/bs_array_test.js @@ -5,6 +5,7 @@ var Block = require("../../lib/js/block.js"); var Bs_List = require("../../lib/js/bs_List.js"); var Js_list = require("../../lib/js/js_list.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); +var Caml_obj = require("../../lib/js/caml_obj.js"); var Js_vector = require("../../lib/js/js_vector.js"); var Caml_array = require("../../lib/js/caml_array.js"); @@ -13,20 +14,11 @@ var suites = [/* [] */0]; var test_id = [0]; function eq(loc, x, y) { - test_id[0] = test_id[0] + 1 | 0; - suites[0] = /* :: */[ - /* tuple */[ - loc + (" id " + test_id[0]), - (function () { - return /* Eq */Block.__(0, [ - x, - y - ]); - }) - ], - suites[0] - ]; - return /* () */0; + return Mt.eq_suites(test_id, suites, loc, x, y); +} + +function b(loc, x) { + return Mt.bool_suites(test_id, suites, loc, x); } function neq(loc, x, y) { @@ -60,10 +52,10 @@ console.log(/* int array */[ }), 0)); function id(x) { - return eq("File \"bs_array_test.ml\", line 26, characters 5-12", Js_vector.toList(Js_list.toVector(x)), x); + return eq("File \"bs_array_test.ml\", line 24, characters 5-12", Js_vector.toList(Js_list.toVector(x)), x); } -eq("File \"bs_array_test.ml\", line 30, characters 5-12", Js_list.toVector(/* :: */[ +eq("File \"bs_array_test.ml\", line 28, characters 5-12", Js_list.toVector(/* :: */[ 1, /* :: */[ 2, @@ -78,7 +70,7 @@ eq("File \"bs_array_test.ml\", line 30, characters 5-12", Js_list.toVector(/* :: 3 ]); -eq("File \"bs_array_test.ml\", line 31, characters 6-13", Js_vector.map((function (x) { +eq("File \"bs_array_test.ml\", line 29, characters 6-13", Js_vector.map((function (x) { return x + 1 | 0; }), /* int array */[ 1, @@ -90,7 +82,7 @@ eq("File \"bs_array_test.ml\", line 31, characters 6-13", Js_vector.map((functio 4 ]); -eq("File \"bs_array_test.ml\", line 34, characters 5-12", Caml_array.caml_make_vect(5, 3), /* array */[ +eq("File \"bs_array_test.ml\", line 32, characters 5-12", Caml_array.caml_make_vect(5, 3), /* array */[ 3, 3, 3, @@ -102,7 +94,7 @@ var a = Js_vector.init(5, (function (i) { return i + 1 | 0; })); -eq("File \"bs_array_test.ml\", line 36, characters 5-12", (Js_vector.filterInPlace((function (j) { +eq("File \"bs_array_test.ml\", line 34, characters 5-12", (Js_vector.filterInPlace((function (j) { return +(j % 2 === 0); }), a), a), /* int array */[ 2, @@ -113,7 +105,7 @@ var a$1 = Js_vector.init(5, (function (i) { return i + 1 | 0; })); -eq("File \"bs_array_test.ml\", line 43, characters 5-12", (Js_vector.filterInPlace((function (j) { +eq("File \"bs_array_test.ml\", line 41, characters 5-12", (Js_vector.filterInPlace((function (j) { return +(j % 2 !== 0); }), a$1), a$1), /* int array */[ 1, @@ -121,7 +113,7 @@ eq("File \"bs_array_test.ml\", line 43, characters 5-12", (Js_vector.filterInPla 5 ]); -eq("File \"bs_array_test.ml\", line 50, characters 5-12", Js_list.toVector(/* :: */[ +eq("File \"bs_array_test.ml\", line 48, characters 5-12", Js_list.toVector(/* :: */[ 1, /* :: */[ 2, @@ -136,7 +128,7 @@ eq("File \"bs_array_test.ml\", line 50, characters 5-12", Js_list.toVector(/* :: 3 ]); -eq("File \"bs_array_test.ml\", line 52, characters 5-12", Js_list.toVector(/* :: */[ +eq("File \"bs_array_test.ml\", line 50, characters 5-12", Js_list.toVector(/* :: */[ 1, /* [] */0 ]), /* int array */[1]); @@ -179,22 +171,58 @@ var v = Bs_Array.makeBy(3000, (function (i) { var u = Bs_Array.shuffle(v); -neq("File \"bs_array_test.ml\", line 63, characters 6-13", u, v); +neq("File \"bs_array_test.ml\", line 61, characters 6-13", u, v); + +eq("File \"bs_array_test.ml\", line 63, characters 5-12", Bs_Array.reduce(u, 0, add), Bs_Array.reduce(v, 0, add)); + +b("File \"bs_array_test.ml\", line 68, characters 4-11", Caml_obj.caml_equal(Bs_Array.range(0, 3), /* int array */[ + 0, + 1, + 2, + 3 + ])); + +b("File \"bs_array_test.ml\", line 69, characters 4-11", Caml_obj.caml_equal(Bs_Array.range(3, 0), /* int array */[])); + +b("File \"bs_array_test.ml\", line 70, characters 4-11", Caml_obj.caml_equal(Bs_Array.range(3, 3), /* int array */[3])); + +b("File \"bs_array_test.ml\", line 72, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(0, 10, 3), /* int array */[ + 0, + 3, + 6, + 9 + ])); + +b("File \"bs_array_test.ml\", line 73, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(0, 12, 3), /* array */[ + 0, + 3, + 6, + 9, + 12 + ])); + +b("File \"bs_array_test.ml\", line 74, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(33, 0, 1), /* int array */[])); + +b("File \"bs_array_test.ml\", line 75, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(33, 0, -1), /* int array */[])); + +b("File \"bs_array_test.ml\", line 76, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(3, 12, -1), /* int array */[])); + +b("File \"bs_array_test.ml\", line 77, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(3, 3, 0), /* int array */[])); -eq("File \"bs_array_test.ml\", line 65, characters 5-12", Bs_Array.reduce(u, 0, add), Bs_Array.reduce(v, 0, add)); +b("File \"bs_array_test.ml\", line 78, characters 4-11", Caml_obj.caml_equal(Bs_Array.rangeBy(3, 3, 1), /* int array */[3])); -eq("File \"bs_array_test.ml\", line 68, characters 5-12", Bs_Array.reduceReverse(/* int array */[], 100, (function (prim, prim$1) { +eq("File \"bs_array_test.ml\", line 83, characters 5-12", Bs_Array.reduceReverse(/* int array */[], 100, (function (prim, prim$1) { return prim - prim$1 | 0; })), 100); -eq("File \"bs_array_test.ml\", line 69, characters 5-12", Bs_Array.reduceReverse(/* int array */[ +eq("File \"bs_array_test.ml\", line 84, characters 5-12", Bs_Array.reduceReverse(/* int array */[ 1, 2 ], 100, (function (prim, prim$1) { return prim - prim$1 | 0; })), 97); -eq("File \"bs_array_test.ml\", line 70, characters 5-12", Bs_Array.reduceReverse(/* int array */[ +eq("File \"bs_array_test.ml\", line 85, characters 5-12", Bs_Array.reduceReverse(/* int array */[ 1, 2, 3, @@ -209,7 +237,7 @@ function addone(x) { function makeMatrixExn(sx, sy, init) { if (!(sx >= 0 && sy >= 0)) { - throw new Error("File \"bs_array_test.ml\", line 75, characters 4-10"); + throw new Error("File \"bs_array_test.ml\", line 90, characters 4-10"); } var res = new Array(sx); for(var x = 0 ,x_finish = sx - 1 | 0; x <= x_finish; ++x){ @@ -222,11 +250,11 @@ function makeMatrixExn(sx, sy, init) { return res; } -eq("File \"bs_array_test.ml\", line 87, characters 5-12", Bs_Array.makeBy(0, (function () { +eq("File \"bs_array_test.ml\", line 102, characters 5-12", Bs_Array.makeBy(0, (function () { return 1; })), /* int array */[]); -eq("File \"bs_array_test.ml\", line 88, characters 5-12", Bs_Array.makeBy(3, (function (i) { +eq("File \"bs_array_test.ml\", line 103, characters 5-12", Bs_Array.makeBy(3, (function (i) { return i; })), /* int array */[ 0, @@ -234,7 +262,7 @@ eq("File \"bs_array_test.ml\", line 88, characters 5-12", Bs_Array.makeBy(3, (fu 2 ]); -eq("File \"bs_array_test.ml\", line 89, characters 5-12", makeMatrixExn(3, 4, 1), /* array */[ +eq("File \"bs_array_test.ml\", line 104, characters 5-12", makeMatrixExn(3, 4, 1), /* array */[ /* int array */[ 1, 1, @@ -255,25 +283,25 @@ eq("File \"bs_array_test.ml\", line 89, characters 5-12", makeMatrixExn(3, 4, 1) ] ]); -eq("File \"bs_array_test.ml\", line 92, characters 5-12", makeMatrixExn(3, 0, 0), /* array */[ +eq("File \"bs_array_test.ml\", line 107, characters 5-12", makeMatrixExn(3, 0, 0), /* array */[ /* int array */[], /* int array */[], /* int array */[] ]); -eq("File \"bs_array_test.ml\", line 93, characters 5-12", makeMatrixExn(0, 3, 1), /* array */[]); +eq("File \"bs_array_test.ml\", line 108, characters 5-12", makeMatrixExn(0, 3, 1), /* array */[]); -eq("File \"bs_array_test.ml\", line 94, characters 5-12", makeMatrixExn(1, 1, 1), /* array */[/* int array */[1]]); +eq("File \"bs_array_test.ml\", line 109, characters 5-12", makeMatrixExn(1, 1, 1), /* array */[/* int array */[1]]); -eq("File \"bs_array_test.ml\", line 95, characters 5-12", Bs_Array.copy(/* array */[]), /* array */[]); +eq("File \"bs_array_test.ml\", line 110, characters 5-12", Bs_Array.copy(/* array */[]), /* array */[]); -eq("File \"bs_array_test.ml\", line 96, characters 5-12", Bs_Array.map(/* int array */[], (function (prim) { +eq("File \"bs_array_test.ml\", line 111, characters 5-12", Bs_Array.map(/* int array */[], (function (prim) { return prim + 1 | 0; })), /* int array */[]); -eq("File \"bs_array_test.ml\", line 97, characters 5-12", Bs_Array.mapWithIndex(/* int array */[], add), /* int array */[]); +eq("File \"bs_array_test.ml\", line 112, characters 5-12", Bs_Array.mapWithIndex(/* int array */[], add), /* int array */[]); -eq("File \"bs_array_test.ml\", line 98, characters 5-12", Bs_Array.mapWithIndex(/* int array */[ +eq("File \"bs_array_test.ml\", line 113, characters 5-12", Bs_Array.mapWithIndex(/* int array */[ 1, 2, 3 @@ -283,14 +311,14 @@ eq("File \"bs_array_test.ml\", line 98, characters 5-12", Bs_Array.mapWithIndex( 5 ]); -eq("File \"bs_array_test.ml\", line 99, characters 5-12", Bs_List.ofArray(/* array */[]), /* [] */0); +eq("File \"bs_array_test.ml\", line 114, characters 5-12", Bs_List.ofArray(/* array */[]), /* [] */0); -eq("File \"bs_array_test.ml\", line 100, characters 5-12", Bs_List.ofArray(/* int array */[1]), /* :: */[ +eq("File \"bs_array_test.ml\", line 115, characters 5-12", Bs_List.ofArray(/* int array */[1]), /* :: */[ 1, /* [] */0 ]); -eq("File \"bs_array_test.ml\", line 101, characters 5-12", Bs_List.ofArray(/* int array */[ +eq("File \"bs_array_test.ml\", line 116, characters 5-12", Bs_List.ofArray(/* int array */[ 1, 2, 3 @@ -305,7 +333,7 @@ eq("File \"bs_array_test.ml\", line 101, characters 5-12", Bs_List.ofArray(/* in ] ]); -eq("File \"bs_array_test.ml\", line 102, characters 5-12", Bs_Array.map(/* int array */[ +eq("File \"bs_array_test.ml\", line 117, characters 5-12", Bs_Array.map(/* int array */[ 1, 2, 3 @@ -317,14 +345,14 @@ eq("File \"bs_array_test.ml\", line 102, characters 5-12", Bs_Array.map(/* int a 4 ]); -eq("File \"bs_array_test.ml\", line 103, characters 5-12", Bs_List.toArray(/* [] */0), /* array */[]); +eq("File \"bs_array_test.ml\", line 118, characters 5-12", Bs_List.toArray(/* [] */0), /* array */[]); -eq("File \"bs_array_test.ml\", line 104, characters 5-12", Bs_List.toArray(/* :: */[ +eq("File \"bs_array_test.ml\", line 119, characters 5-12", Bs_List.toArray(/* :: */[ 1, /* [] */0 ]), /* int array */[1]); -eq("File \"bs_array_test.ml\", line 105, characters 5-12", Bs_List.toArray(/* :: */[ +eq("File \"bs_array_test.ml\", line 120, characters 5-12", Bs_List.toArray(/* :: */[ 1, /* :: */[ 2, @@ -335,7 +363,7 @@ eq("File \"bs_array_test.ml\", line 105, characters 5-12", Bs_List.toArray(/* :: 2 ]); -eq("File \"bs_array_test.ml\", line 106, characters 5-12", Bs_List.toArray(/* :: */[ +eq("File \"bs_array_test.ml\", line 121, characters 5-12", Bs_List.toArray(/* :: */[ 1, /* :: */[ 2, @@ -370,7 +398,7 @@ var v2 = Bs_Array.keepMap(v$1, (function (x) { } })); -eq("File \"bs_array_test.ml\", line 113, characters 5-12", v0, /* array */[ +eq("File \"bs_array_test.ml\", line 128, characters 5-12", v0, /* array */[ 0, 2, 4, @@ -378,14 +406,14 @@ eq("File \"bs_array_test.ml\", line 113, characters 5-12", v0, /* array */[ 8 ]); -eq("File \"bs_array_test.ml\", line 114, characters 5-12", v1, /* int array */[ +eq("File \"bs_array_test.ml\", line 129, characters 5-12", v1, /* int array */[ 0, 3, 6, 9 ]); -eq("File \"bs_array_test.ml\", line 115, characters 5-12", v2, /* array */[ +eq("File \"bs_array_test.ml\", line 130, characters 5-12", v2, /* array */[ 1, 3, 5, @@ -401,12 +429,12 @@ var a$2 = /* array */[ 5 ]; -eq("File \"bs_array_test.ml\", line 119, characters 5-12", Bs_Array.slice(a$2, 0, 2), /* int array */[ +eq("File \"bs_array_test.ml\", line 134, characters 5-12", Bs_Array.slice(a$2, 0, 2), /* int array */[ 1, 2 ]); -eq("File \"bs_array_test.ml\", line 120, characters 5-12", Bs_Array.slice(a$2, 0, 5), /* array */[ +eq("File \"bs_array_test.ml\", line 135, characters 5-12", Bs_Array.slice(a$2, 0, 5), /* array */[ 1, 2, 3, @@ -414,7 +442,7 @@ eq("File \"bs_array_test.ml\", line 120, characters 5-12", Bs_Array.slice(a$2, 0 5 ]); -eq("File \"bs_array_test.ml\", line 121, characters 5-12", Bs_Array.slice(a$2, 0, 15), /* array */[ +eq("File \"bs_array_test.ml\", line 136, characters 5-12", Bs_Array.slice(a$2, 0, 15), /* array */[ 1, 2, 3, @@ -422,40 +450,40 @@ eq("File \"bs_array_test.ml\", line 121, characters 5-12", Bs_Array.slice(a$2, 0 5 ]); -eq("File \"bs_array_test.ml\", line 122, characters 5-12", Bs_Array.slice(a$2, 5, 1), /* int array */[]); +eq("File \"bs_array_test.ml\", line 137, characters 5-12", Bs_Array.slice(a$2, 5, 1), /* int array */[]); -eq("File \"bs_array_test.ml\", line 123, characters 5-12", Bs_Array.slice(a$2, 4, 1), /* int array */[5]); +eq("File \"bs_array_test.ml\", line 138, characters 5-12", Bs_Array.slice(a$2, 4, 1), /* int array */[5]); -eq("File \"bs_array_test.ml\", line 124, characters 5-12", Bs_Array.slice(a$2, -1, 1), /* int array */[5]); +eq("File \"bs_array_test.ml\", line 139, characters 5-12", Bs_Array.slice(a$2, -1, 1), /* int array */[5]); -eq("File \"bs_array_test.ml\", line 125, characters 5-12", Bs_Array.slice(a$2, -1, 2), /* int array */[5]); +eq("File \"bs_array_test.ml\", line 140, characters 5-12", Bs_Array.slice(a$2, -1, 2), /* int array */[5]); -eq("File \"bs_array_test.ml\", line 126, characters 5-12", Bs_Array.slice(a$2, -2, 1), /* int array */[4]); +eq("File \"bs_array_test.ml\", line 141, characters 5-12", Bs_Array.slice(a$2, -2, 1), /* int array */[4]); -eq("File \"bs_array_test.ml\", line 127, characters 5-12", Bs_Array.slice(a$2, -2, 2), /* int array */[ +eq("File \"bs_array_test.ml\", line 142, characters 5-12", Bs_Array.slice(a$2, -2, 2), /* int array */[ 4, 5 ]); -eq("File \"bs_array_test.ml\", line 128, characters 5-12", Bs_Array.slice(a$2, -2, 3), /* int array */[ +eq("File \"bs_array_test.ml\", line 143, characters 5-12", Bs_Array.slice(a$2, -2, 3), /* int array */[ 4, 5 ]); -eq("File \"bs_array_test.ml\", line 129, characters 5-12", Bs_Array.slice(a$2, -10, 3), /* int array */[ +eq("File \"bs_array_test.ml\", line 144, characters 5-12", Bs_Array.slice(a$2, -10, 3), /* int array */[ 1, 2, 3 ]); -eq("File \"bs_array_test.ml\", line 130, characters 5-12", Bs_Array.slice(a$2, -10, 4), /* int array */[ +eq("File \"bs_array_test.ml\", line 145, characters 5-12", Bs_Array.slice(a$2, -10, 4), /* int array */[ 1, 2, 3, 4 ]); -eq("File \"bs_array_test.ml\", line 131, characters 5-12", Bs_Array.slice(a$2, -10, 5), /* array */[ +eq("File \"bs_array_test.ml\", line 146, characters 5-12", Bs_Array.slice(a$2, -10, 5), /* array */[ 1, 2, 3, @@ -463,7 +491,7 @@ eq("File \"bs_array_test.ml\", line 131, characters 5-12", Bs_Array.slice(a$2, - 5 ]); -eq("File \"bs_array_test.ml\", line 132, characters 5-12", Bs_Array.slice(a$2, -10, 6), /* array */[ +eq("File \"bs_array_test.ml\", line 147, characters 5-12", Bs_Array.slice(a$2, -10, 6), /* array */[ 1, 2, 3, @@ -471,9 +499,9 @@ eq("File \"bs_array_test.ml\", line 132, characters 5-12", Bs_Array.slice(a$2, - 5 ]); -eq("File \"bs_array_test.ml\", line 133, characters 5-12", Bs_Array.slice(a$2, 0, 0), /* int array */[]); +eq("File \"bs_array_test.ml\", line 148, characters 5-12", Bs_Array.slice(a$2, 0, 0), /* int array */[]); -eq("File \"bs_array_test.ml\", line 134, characters 5-12", Bs_Array.slice(a$2, 0, -1), /* int array */[]); +eq("File \"bs_array_test.ml\", line 149, characters 5-12", Bs_Array.slice(a$2, 0, -1), /* int array */[]); var a$3 = Bs_Array.makeBy(10, (function (x) { return x; @@ -481,7 +509,7 @@ var a$3 = Bs_Array.makeBy(10, (function (x) { Bs_Array.fill(a$3, 0, 3, 0); -eq("File \"bs_array_test.ml\", line 139, characters 6-13", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 154, characters 6-13", Bs_Array.copy(a$3), /* array */[ 0, 0, 0, @@ -496,7 +524,7 @@ eq("File \"bs_array_test.ml\", line 139, characters 6-13", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, 2, 8, 1); -eq("File \"bs_array_test.ml\", line 141, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 156, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -511,7 +539,7 @@ eq("File \"bs_array_test.ml\", line 141, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, 8, 1, 9); -eq("File \"bs_array_test.ml\", line 143, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 158, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -526,7 +554,7 @@ eq("File \"bs_array_test.ml\", line 143, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, 8, 2, 9); -eq("File \"bs_array_test.ml\", line 145, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 160, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -541,7 +569,7 @@ eq("File \"bs_array_test.ml\", line 145, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, 8, 3, 12); -eq("File \"bs_array_test.ml\", line 147, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 162, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -556,7 +584,7 @@ eq("File \"bs_array_test.ml\", line 147, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, -2, 3, 11); -eq("File \"bs_array_test.ml\", line 149, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 164, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -571,7 +599,7 @@ eq("File \"bs_array_test.ml\", line 149, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, -3, 3, 10); -eq("File \"bs_array_test.ml\", line 151, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 166, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -586,7 +614,7 @@ eq("File \"bs_array_test.ml\", line 151, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, -3, 1, 7); -eq("File \"bs_array_test.ml\", line 153, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 168, characters 5-12", Bs_Array.copy(a$3), /* array */[ 0, 0, 1, @@ -601,7 +629,7 @@ eq("File \"bs_array_test.ml\", line 153, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, -13, 1, 7); -eq("File \"bs_array_test.ml\", line 155, characters 5-12", Bs_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 170, characters 5-12", Bs_Array.copy(a$3), /* array */[ 7, 0, 1, @@ -616,11 +644,11 @@ eq("File \"bs_array_test.ml\", line 155, characters 5-12", Bs_Array.copy(a$3), / Bs_Array.fill(a$3, -13, 12, 7); -eq("File \"bs_array_test.ml\", line 157, characters 5-12", Bs_Array.copy(a$3), Bs_Array.make(10, 7)); +eq("File \"bs_array_test.ml\", line 172, characters 5-12", Bs_Array.copy(a$3), Bs_Array.make(10, 7)); Bs_Array.fill(a$3, 0, -1, 2); -eq("File \"bs_array_test.ml\", line 159, characters 5-12", Bs_Array.copy(a$3), Bs_Array.make(10, 7)); +eq("File \"bs_array_test.ml\", line 174, characters 5-12", Bs_Array.copy(a$3), Bs_Array.make(10, 7)); var a0 = Bs_Array.makeBy(10, (function (x) { return x; @@ -630,7 +658,7 @@ var b0 = Bs_Array.make(10, 3); Bs_Array.blit(a0, 1, b0, 2, 5); -eq("File \"bs_array_test.ml\", line 165, characters 5-12", Bs_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 180, characters 5-12", Bs_Array.copy(b0), /* array */[ 3, 3, 1, @@ -645,7 +673,7 @@ eq("File \"bs_array_test.ml\", line 165, characters 5-12", Bs_Array.copy(b0), /* Bs_Array.blit(a0, -1, b0, 2, 5); -eq("File \"bs_array_test.ml\", line 168, characters 5-12", Bs_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 183, characters 5-12", Bs_Array.copy(b0), /* array */[ 3, 3, 9, @@ -660,7 +688,7 @@ eq("File \"bs_array_test.ml\", line 168, characters 5-12", Bs_Array.copy(b0), /* Bs_Array.blit(a0, -1, b0, -2, 5); -eq("File \"bs_array_test.ml\", line 171, characters 5-12", Bs_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 186, characters 5-12", Bs_Array.copy(b0), /* array */[ 3, 3, 9, @@ -675,7 +703,7 @@ eq("File \"bs_array_test.ml\", line 171, characters 5-12", Bs_Array.copy(b0), /* Bs_Array.blit(a0, -2, b0, -2, 2); -eq("File \"bs_array_test.ml\", line 174, characters 5-12", Bs_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 189, characters 5-12", Bs_Array.copy(b0), /* array */[ 3, 3, 9, @@ -690,11 +718,11 @@ eq("File \"bs_array_test.ml\", line 174, characters 5-12", Bs_Array.copy(b0), /* Bs_Array.blit(a0, -11, b0, -11, 100); -eq("File \"bs_array_test.ml\", line 177, characters 5-12", Bs_Array.copy(b0), a0); +eq("File \"bs_array_test.ml\", line 192, characters 5-12", Bs_Array.copy(b0), a0); Bs_Array.blit(a0, -11, b0, -11, 2); -eq("File \"bs_array_test.ml\", line 179, characters 5-12", Bs_Array.copy(b0), a0); +eq("File \"bs_array_test.ml\", line 194, characters 5-12", Bs_Array.copy(b0), a0); var aa = Bs_Array.makeBy(10, (function (x) { return x; @@ -702,7 +730,7 @@ var aa = Bs_Array.makeBy(10, (function (x) { Bs_Array.blit(aa, -1, aa, 1, 2); -eq("File \"bs_array_test.ml\", line 182, characters 5-12", Bs_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 197, characters 5-12", Bs_Array.copy(aa), /* array */[ 0, 9, 2, @@ -717,7 +745,7 @@ eq("File \"bs_array_test.ml\", line 182, characters 5-12", Bs_Array.copy(aa), /* Bs_Array.blit(aa, -2, aa, 1, 2); -eq("File \"bs_array_test.ml\", line 184, characters 5-12", Bs_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 199, characters 5-12", Bs_Array.copy(aa), /* array */[ 0, 8, 9, @@ -732,7 +760,7 @@ eq("File \"bs_array_test.ml\", line 184, characters 5-12", Bs_Array.copy(aa), /* Bs_Array.blit(aa, -5, aa, 4, 3); -eq("File \"bs_array_test.ml\", line 186, characters 5-12", Bs_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 201, characters 5-12", Bs_Array.copy(aa), /* array */[ 0, 8, 9, @@ -747,7 +775,7 @@ eq("File \"bs_array_test.ml\", line 186, characters 5-12", Bs_Array.copy(aa), /* Bs_Array.blit(aa, 4, aa, 5, 3); -eq("File \"bs_array_test.ml\", line 188, characters 5-12", Bs_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 203, characters 5-12", Bs_Array.copy(aa), /* array */[ 0, 8, 9, @@ -762,25 +790,25 @@ eq("File \"bs_array_test.ml\", line 188, characters 5-12", Bs_Array.copy(aa), /* function id$1(_, x) { var u = Bs_Array.copy(x); - return eq("File \"bs_array_test.ml\", line 191, characters 5-12", Bs_Array.reverse(x), (Bs_Array.reverseInPlace(u), u)); + return eq("File \"bs_array_test.ml\", line 206, characters 5-12", Bs_Array.reverse(x), (Bs_Array.reverseInPlace(u), u)); } -id$1("File \"bs_array_test.ml\", line 196, characters 5-12", /* array */[]); +id$1("File \"bs_array_test.ml\", line 211, characters 5-12", /* array */[]); -id$1("File \"bs_array_test.ml\", line 197, characters 5-12", /* int array */[1]); +id$1("File \"bs_array_test.ml\", line 212, characters 5-12", /* int array */[1]); -id$1("File \"bs_array_test.ml\", line 198, characters 5-12", /* int array */[ +id$1("File \"bs_array_test.ml\", line 213, characters 5-12", /* int array */[ 1, 2 ]); -id$1("File \"bs_array_test.ml\", line 199, characters 5-12", /* int array */[ +id$1("File \"bs_array_test.ml\", line 214, characters 5-12", /* int array */[ 1, 2, 3 ]); -id$1("File \"bs_array_test.ml\", line 200, characters 5-12", /* int array */[ +id$1("File \"bs_array_test.ml\", line 215, characters 5-12", /* int array */[ 1, 2, 3, @@ -803,14 +831,14 @@ function some2(xs, ys) { }); } -eq("File \"bs_array_test.ml\", line 210, characters 5-12", every2(/* [] */0, /* :: */[ +eq("File \"bs_array_test.ml\", line 225, characters 5-12", every2(/* [] */0, /* :: */[ 1, /* [] */0 ])((function (x, y) { return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 211, characters 5-12", every2(/* :: */[ +eq("File \"bs_array_test.ml\", line 226, characters 5-12", every2(/* :: */[ 2, /* :: */[ 3, @@ -823,7 +851,7 @@ eq("File \"bs_array_test.ml\", line 211, characters 5-12", every2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 212, characters 5-12", every2(/* :: */[ +eq("File \"bs_array_test.ml\", line 227, characters 5-12", every2(/* :: */[ 2, /* [] */0 ], /* :: */[ @@ -833,7 +861,7 @@ eq("File \"bs_array_test.ml\", line 212, characters 5-12", every2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 213, characters 5-12", every2(/* :: */[ +eq("File \"bs_array_test.ml\", line 228, characters 5-12", every2(/* :: */[ 2, /* :: */[ 3, @@ -849,7 +877,7 @@ eq("File \"bs_array_test.ml\", line 213, characters 5-12", every2(/* :: */[ return +(x > y); })), /* false */0); -eq("File \"bs_array_test.ml\", line 214, characters 5-12", every2(/* :: */[ +eq("File \"bs_array_test.ml\", line 229, characters 5-12", every2(/* :: */[ 2, /* :: */[ 3, @@ -865,14 +893,14 @@ eq("File \"bs_array_test.ml\", line 214, characters 5-12", every2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 215, characters 5-12", some2(/* [] */0, /* :: */[ +eq("File \"bs_array_test.ml\", line 230, characters 5-12", some2(/* [] */0, /* :: */[ 1, /* [] */0 ])((function (x, y) { return +(x > y); })), /* false */0); -eq("File \"bs_array_test.ml\", line 216, characters 5-12", some2(/* :: */[ +eq("File \"bs_array_test.ml\", line 231, characters 5-12", some2(/* :: */[ 2, /* :: */[ 3, @@ -885,7 +913,7 @@ eq("File \"bs_array_test.ml\", line 216, characters 5-12", some2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 217, characters 5-12", some2(/* :: */[ +eq("File \"bs_array_test.ml\", line 232, characters 5-12", some2(/* :: */[ 2, /* :: */[ 3, @@ -901,7 +929,7 @@ eq("File \"bs_array_test.ml\", line 217, characters 5-12", some2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 218, characters 5-12", some2(/* :: */[ +eq("File \"bs_array_test.ml\", line 233, characters 5-12", some2(/* :: */[ 0, /* :: */[ 3, @@ -917,7 +945,7 @@ eq("File \"bs_array_test.ml\", line 218, characters 5-12", some2(/* :: */[ return +(x > y); })), /* false */0); -eq("File \"bs_array_test.ml\", line 219, characters 5-12", some2(/* :: */[ +eq("File \"bs_array_test.ml\", line 234, characters 5-12", some2(/* :: */[ 0, /* :: */[ 3, @@ -933,7 +961,7 @@ eq("File \"bs_array_test.ml\", line 219, characters 5-12", some2(/* :: */[ return +(x > y); })), /* true */1); -eq("File \"bs_array_test.ml\", line 224, characters 5-12", Bs_Array.concat(/* int array */[], /* int array */[ +eq("File \"bs_array_test.ml\", line 239, characters 5-12", Bs_Array.concat(/* int array */[], /* int array */[ 1, 2, 3 @@ -943,9 +971,9 @@ eq("File \"bs_array_test.ml\", line 224, characters 5-12", Bs_Array.concat(/* in 3 ]); -eq("File \"bs_array_test.ml\", line 225, characters 5-12", Bs_Array.concat(/* array */[], /* array */[]), /* array */[]); +eq("File \"bs_array_test.ml\", line 240, characters 5-12", Bs_Array.concat(/* array */[], /* array */[]), /* array */[]); -eq("File \"bs_array_test.ml\", line 226, characters 5-12", Bs_Array.concat(/* int array */[ +eq("File \"bs_array_test.ml\", line 241, characters 5-12", Bs_Array.concat(/* int array */[ 3, 2 ], /* int array */[ @@ -960,7 +988,7 @@ eq("File \"bs_array_test.ml\", line 226, characters 5-12", Bs_Array.concat(/* in 3 ]); -eq("File \"bs_array_test.ml\", line 227, characters 5-12", Bs_Array.concatMany(/* array */[ +eq("File \"bs_array_test.ml\", line 242, characters 5-12", Bs_Array.concatMany(/* array */[ /* int array */[ 3, 2 @@ -978,7 +1006,7 @@ eq("File \"bs_array_test.ml\", line 227, characters 5-12", Bs_Array.concatMany(/ 3 ]); -eq("File \"bs_array_test.ml\", line 228, characters 5-12", Bs_Array.concatMany(/* array */[ +eq("File \"bs_array_test.ml\", line 243, characters 5-12", Bs_Array.concatMany(/* array */[ /* int array */[ 3, 2 @@ -999,7 +1027,7 @@ eq("File \"bs_array_test.ml\", line 228, characters 5-12", Bs_Array.concatMany(/ 0 ]); -eq("File \"bs_array_test.ml\", line 229, characters 5-12", Bs_Array.concatMany(/* array */[ +eq("File \"bs_array_test.ml\", line 244, characters 5-12", Bs_Array.concatMany(/* array */[ /* int array */[], /* int array */[ 3, @@ -1021,12 +1049,12 @@ eq("File \"bs_array_test.ml\", line 229, characters 5-12", Bs_Array.concatMany(/ 0 ]); -eq("File \"bs_array_test.ml\", line 230, characters 5-12", Bs_Array.concatMany(/* array */[ +eq("File \"bs_array_test.ml\", line 245, characters 5-12", Bs_Array.concatMany(/* array */[ /* array */[], /* array */[] ]), /* array */[]); -Mt.from_pair_suites("File \"bs_array_test.ml\", line 232, characters 23-30", suites[0]); +Mt.from_pair_suites("File \"bs_array_test.ml\", line 247, characters 23-30", suites[0]); var A = 0; @@ -1035,6 +1063,7 @@ var L = 0; exports.suites = suites; exports.test_id = test_id; exports.eq = eq; +exports.b = b; exports.neq = neq; exports.A = A; exports.L = L; diff --git a/jscomp/test/bs_array_test.ml b/jscomp/test/bs_array_test.ml index 2cec95a24b..be14b7059c 100644 --- a/jscomp/test/bs_array_test.ml +++ b/jscomp/test/bs_array_test.ml @@ -1,10 +1,8 @@ let suites : Mt.pair_suites ref = ref [] let test_id = ref 0 -let eq loc x y = - incr test_id ; - suites := - (loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites +let eq loc x y = Mt.eq_suites loc x y ~test_id ~suites +let b loc x = Mt.bool_suites loc x ~test_id ~suites let neq loc x y = incr test_id ; suites := @@ -64,6 +62,23 @@ let () = let sum x = A.reduce x 0 add in eq __LOC__ ( sum u) (sum v) + +let () = + let open A in + b __LOC__ (range 0 3 = [|0;1;2;3|]); + b __LOC__ (range 3 0 = [||] ); + b __LOC__ (range 3 3 = [|3|]); + + b __LOC__ (rangeBy 0 10 ~step:3 = [|0;3;6;9|]); + b __LOC__ (rangeBy 0 12 ~step:3 = [|0;3;6;9;12|]); + b __LOC__ (rangeBy 33 0 ~step:1 = [||]); + b __LOC__ (rangeBy 33 0 ~step:(-1) = [||]); + b __LOC__ (rangeBy 3 12 ~step:(-1) = [||]); + b __LOC__ (rangeBy 3 3 ~step:0 = [||] ); + b __LOC__ (rangeBy 3 3 ~step:(1) = [|3|]) + + + let () = eq __LOC__ (A.reduceReverse [||] 100 (-)) 100; eq __LOC__ (A.reduceReverse [|1;2|] 100 (-)) 97; diff --git a/jscomp/test/bs_hashmap_test.js b/jscomp/test/bs_hashmap_test.js index 15e345c4b0..e7c7a75c1a 100644 --- a/jscomp/test/bs_hashmap_test.js +++ b/jscomp/test/bs_hashmap_test.js @@ -1,7 +1,7 @@ 'use strict'; var Mt = require("./mt.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Hashtbl = require("../../lib/js/hashtbl.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Bs_HashMap = require("../../lib/js/bs_HashMap.js"); @@ -29,7 +29,7 @@ var hash = Hashtbl.hash; var cmp = Caml_primitive.caml_int_compare; -var Y = Bs_Dict.hashable(hash, eq); +var Y = Bs_Id.hashable(hash, eq); var empty = Bs_HashMap.make(30, Y); diff --git a/jscomp/test/bs_hashmap_test.ml b/jscomp/test/bs_hashmap_test.ml index 920d5f47a1..e3946d3084 100644 --- a/jscomp/test/bs_hashmap_test.ml +++ b/jscomp/test/bs_hashmap_test.ml @@ -11,7 +11,7 @@ module S = Bs.Map.Int let eq = fun (x : int) y -> x = y let hash = fun (x : int) -> Hashtbl.hash x let cmp = fun (x : int) y -> compare x y -module Y = (val Bs.Dict.hashable ~eq ~hash) +module Y = (val Bs.Id.hashable ~eq ~hash) let empty : (int, int, _) N.t = N.make ~dict:(module Y) 30 (* diff --git a/jscomp/test/bs_hashtbl_string_test.js b/jscomp/test/bs_hashtbl_string_test.js index 0fdeb094a6..30697eecc7 100644 --- a/jscomp/test/bs_hashtbl_string_test.js +++ b/jscomp/test/bs_hashtbl_string_test.js @@ -1,6 +1,6 @@ 'use strict'; -var Bs_Dict = require("../../lib/js/bs_Dict.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Hashtbl = require("../../lib/js/hashtbl.js"); var Caml_hash = require("../../lib/js/caml_hash.js"); var Bs_HashMap = require("../../lib/js/bs_HashMap.js"); @@ -27,21 +27,21 @@ var hashString = (function (str) { } ); -var $$String = Bs_Dict.hashable(Hashtbl.hash, (function (x, y) { +var $$String = Bs_Id.hashable(Hashtbl.hash, (function (x, y) { return +(x === y); })); -var String1 = Bs_Dict.hashable(hashString, (function (x, y) { +var String1 = Bs_Id.hashable(hashString, (function (x, y) { return +(x === y); })); -var String2 = Bs_Dict.hashable((function (x) { +var String2 = Bs_Id.hashable((function (x) { return Caml_hash.caml_hash_final_mix(Caml_hash.caml_hash_mix_string(0, x)); }), (function (x, y) { return +(x === y); })); -var Int = Bs_Dict.hashable(Hashtbl.hash, (function (x, y) { +var Int = Bs_Id.hashable(Hashtbl.hash, (function (x, y) { return +(x === y); })); @@ -142,7 +142,7 @@ function bench3(m) { } } -var Sx = Bs_Dict.comparable(Caml_primitive.caml_string_compare); +var Sx = Bs_Id.comparable(Caml_primitive.caml_string_compare); function bench4() { var table = Bs_internalBucketsType.make(/* () */0, /* () */0, 1000000); diff --git a/jscomp/test/bs_hashtbl_string_test.ml b/jscomp/test/bs_hashtbl_string_test.ml index 268a05da71..dd47575731 100644 --- a/jscomp/test/bs_hashtbl_string_test.ml +++ b/jscomp/test/bs_hashtbl_string_test.ml @@ -18,21 +18,21 @@ let hashString : string -> int = [%raw{|function (str) { |}] module String = - (val Bs.Dict.hashable + (val Bs.Id.hashable ~eq:(fun (x:string) y -> x = y ) ~hash:Hashtbl.hash) module String1 = - (val Bs.Dict.hashable + (val Bs.Id.hashable ~eq:(fun (x:string) y -> x = y ) ~hash:hashString) module String2 = - (val Bs.Dict.hashable + (val Bs.Id.hashable ~eq:(fun (x:string) y -> x = y ) ~hash:(fun (x:string) -> hash_string x)) module Int = - (val Bs.Dict.hashable + (val Bs.Id.hashable ~eq:(fun (x:int) y -> x = y ) ~hash:Hashtbl.hash) module N = Bs.HashMap @@ -61,7 +61,7 @@ let initial_size = 1_000_000 #.add (string_of_int i) i *) module M = Bs.HashMap -let bench2 (type t) (m : (string,t) Bs.Dict.hashable) = +let bench2 (type t) (m : (string,t) Bs.Id.hashable) = let empty = M.make ~dict:m initial_size in let module String = (val m) in @@ -84,7 +84,7 @@ let bench2 (type t) (m : (string,t) Bs.Dict.hashable) = (* Bs.HashMap.logStats empty *) module Md = Bs.Map module Md0 = Bs.Map.Dict -let bench3 (type t) (m : (string,t) Bs.Dict.comparable) = +let bench3 (type t) (m : (string,t) Bs.Id.comparable) = let empty = Md.make m in let module String = (val m) in @@ -104,7 +104,7 @@ let bench3 (type t) (m : (string,t) Bs.Dict.comparable) = done ; assert (Md0.size !table = 0) -module Sx = (val Bs.Dict.comparable ~cmp:(fun (x : string) y -> compare x y )) +module Sx = (val Bs.Id.comparable ~cmp:(fun (x : string) y -> compare x y )) module H = Bs.HashMap.String let bench4 () = let table = diff --git a/jscomp/test/bs_map_set_dict_test.js b/jscomp/test/bs_map_set_dict_test.js index 14f65168f5..3a6d91a752 100644 --- a/jscomp/test/bs_map_set_dict_test.js +++ b/jscomp/test/bs_map_set_dict_test.js @@ -1,8 +1,8 @@ 'use strict'; var Mt = require("./mt.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Bs_Map = require("../../lib/js/bs_Map.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); var Bs_List = require("../../lib/js/bs_List.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Bs_MapInt = require("../../lib/js/bs_MapInt.js"); @@ -23,16 +23,16 @@ function b(loc, v) { return Mt.bool_suites(test_id, suites, loc, v); } -var Icmp = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var Icmp = Bs_Id.comparable(Caml_primitive.caml_int_compare); -var Icmp2 = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var Icmp2 = Bs_Id.comparable(Caml_primitive.caml_int_compare); var m0 = { cmp: Icmp[/* cmp */0], data: Bs_MapDict.empty }; -var I2 = Bs_Dict.comparable((function (x, y) { +var I2 = Bs_Id.comparable((function (x, y) { return Caml_primitive.caml_int_compare(y, x); })); @@ -48,9 +48,9 @@ var m2 = { var data = m.data; -Bs_Map.getDict(m2); +Bs_Map.getId(m2); -var m_dict = Bs_Map.getDict(m); +var m_dict = Bs_Map.getId(m); for(var i = 0; i <= 100000; ++i){ data = Bs_MapDict.set(data, i, i, m_dict[/* cmp */0]); @@ -74,7 +74,7 @@ var v = { data: Bs_SetDict.empty }; -var m_dict$1 = Bs_Map.getDict(m); +var m_dict$1 = Bs_Map.getId(m); var cmp = m_dict$1[/* cmp */0]; diff --git a/jscomp/test/bs_map_set_dict_test.ml b/jscomp/test/bs_map_set_dict_test.ml index 74c0314a3d..dbac0d45c1 100644 --- a/jscomp/test/bs_map_set_dict_test.ml +++ b/jscomp/test/bs_map_set_dict_test.ml @@ -4,13 +4,13 @@ let eq loc x y = Mt.eq_suites ~suites ~test_id loc x y let b loc v = Mt.bool_suites ~suites ~test_id loc v module Icmp = - (val Bs.Dict.comparable + (val Bs.Id.comparable ~cmp:(fun (x : int) y -> compare x y ) ) module Icmp2 = -(val Bs.Dict.comparable ~cmp:(fun (x : int) y -> +(val Bs.Id.comparable ~cmp:(fun (x : int) y -> compare x y )) module M = Bs.Map @@ -23,7 +23,7 @@ let m0 : (_,string,_) M.t = M.make (module Icmp) module I2 = -(val Bs.Dict.comparable ~cmp:(fun (x : int) y -> compare y x )) +(val Bs.Id.comparable ~cmp:(fun (x : int) y -> compare y x )) let m = M.make (module Icmp2) @@ -34,7 +34,7 @@ module Md0 = Bs.Map.Dict let () = let count = 1_000_00 in let data = ref (M.getData m) in - let m2_dict, m_dict = M.(getDict m2, getDict m) in + let m2_dict, m_dict = M.(getId m2, getId m) in let module N = (val m2_dict) in let module Mm = ( val m_dict) in for i = 0 to count do @@ -43,7 +43,7 @@ let () = ~cmp: Mm.cmp i i done ; - let newm = M.packDictData ~data:!data ~dict:m_dict in + let newm = M.packIdData ~data:!data ~id:m_dict in Js.log newm module ISet = Bs.Set let () = @@ -59,7 +59,7 @@ module S0 = Bs.Set.Dict let () = let count = 100_000 in let v = ISet.make (module Icmp2) in - let m_dict = M.getDict m in + let m_dict = M.getId m in let module M = (val m_dict) in let cmp = M.cmp in let data = ref (ISet.getData v) in @@ -68,7 +68,7 @@ let () = done ; Js.log !data -let f = M.ofArray ~dict:(module Icmp) +let f = M.ofArray ~id:(module Icmp) let (=~) a b = M.eq a b let () = diff --git a/jscomp/test/bs_poly_map_test.js b/jscomp/test/bs_poly_map_test.js index 80690ba6e8..3bf0d2ba85 100644 --- a/jscomp/test/bs_poly_map_test.js +++ b/jscomp/test/bs_poly_map_test.js @@ -1,9 +1,9 @@ 'use strict'; var Mt = require("./mt.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Bs_Map = require("../../lib/js/bs_Map.js"); var Bs_Set = require("../../lib/js/bs_Set.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Caml_obj = require("../../lib/js/caml_obj.js"); var Bs_MapDict = require("../../lib/js/bs_MapDict.js"); @@ -22,7 +22,7 @@ function b(loc, v) { return Mt.bool_suites(test_id, suites, loc, v); } -var Icmp = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var Icmp = Bs_Id.comparable(Caml_primitive.caml_int_compare); function mapOfArray(x) { return Bs_Map.ofArray(x, Icmp); diff --git a/jscomp/test/bs_poly_map_test.ml b/jscomp/test/bs_poly_map_test.ml index dda5757151..d2e7febde4 100644 --- a/jscomp/test/bs_poly_map_test.ml +++ b/jscomp/test/bs_poly_map_test.ml @@ -4,7 +4,7 @@ let eq loc x y = Mt.eq_suites ~suites ~test_id loc x y let b loc v = Mt.bool_suites ~suites ~test_id loc v module Icmp = - (val Bs.Dict.comparable + (val Bs.Id.comparable (fun (x : int) y -> compare x y) ) module M = Bs.Map @@ -14,7 +14,7 @@ module A = Bs_Array module I = Array_data_util -let mapOfArray x = M.ofArray ~dict:(module Icmp) x +let mapOfArray x = M.ofArray ~id:(module Icmp) x let setOfArray x = N.ofArray ~dict:(module Icmp) x let emptyMap () = M.make (module Icmp) diff --git a/jscomp/test/bs_poly_mutable_map_test.js b/jscomp/test/bs_poly_mutable_map_test.js index eb88b42cf8..994478ba0c 100644 --- a/jscomp/test/bs_poly_mutable_map_test.js +++ b/jscomp/test/bs_poly_mutable_map_test.js @@ -1,8 +1,8 @@ 'use strict'; var Mt = require("./mt.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Bs_Set = require("../../lib/js/bs_Set.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Bs_MutableMap = require("../../lib/js/bs_MutableMap.js"); var Caml_primitive = require("../../lib/js/caml_primitive.js"); @@ -21,7 +21,7 @@ function b(loc, v) { return Mt.bool_suites(test_id, suites, loc, v); } -var Icmp = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var Icmp = Bs_Id.comparable(Caml_primitive.caml_int_compare); function f(x) { return Bs_MutableMap.ofArray(x, Icmp); diff --git a/jscomp/test/bs_poly_mutable_map_test.ml b/jscomp/test/bs_poly_mutable_map_test.ml index f1cc50a6ef..09ec758dfe 100644 --- a/jscomp/test/bs_poly_mutable_map_test.ml +++ b/jscomp/test/bs_poly_mutable_map_test.ml @@ -4,7 +4,7 @@ let eq loc x y = Mt.eq_suites ~suites ~test_id loc x y let b loc v = Mt.bool_suites ~suites ~test_id loc v module Icmp = - (val Bs.Dict.comparable + (val Bs.Id.comparable (fun (x : int) y -> compare x y ) ) diff --git a/jscomp/test/bs_poly_mutable_set_test.js b/jscomp/test/bs_poly_mutable_set_test.js index 69da7caa3e..c56216bfb7 100644 --- a/jscomp/test/bs_poly_mutable_set_test.js +++ b/jscomp/test/bs_poly_mutable_set_test.js @@ -1,7 +1,7 @@ 'use strict'; var Mt = require("./mt.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Bs_List = require("../../lib/js/bs_List.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Caml_obj = require("../../lib/js/caml_obj.js"); @@ -22,7 +22,7 @@ function b(loc, x) { return Mt.bool_suites(test_id, suites, loc, x); } -var IntCmp = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var IntCmp = Bs_Id.comparable(Caml_primitive.caml_int_compare); function ofArray(param) { return Bs_MutableSet.ofArray(param, IntCmp); diff --git a/jscomp/test/bs_poly_mutable_set_test.ml b/jscomp/test/bs_poly_mutable_set_test.ml index ee68b85f83..b746feca12 100644 --- a/jscomp/test/bs_poly_mutable_set_test.ml +++ b/jscomp/test/bs_poly_mutable_set_test.ml @@ -7,7 +7,7 @@ module N = Bs.MutableSet module I = Array_data_util module A = Bs.Array module IntCmp = - (val Bs.Dict.comparable (fun (x:int) y -> compare x y)) + (val Bs.Id.comparable (fun (x:int) y -> compare x y)) module L = Bs.List let ofArray = N.ofArray ~dict:(module IntCmp) let empty () = N.make ~dict:(module IntCmp) diff --git a/jscomp/test/bs_poly_set_test.js b/jscomp/test/bs_poly_set_test.js index 854c97fe0f..f0089b767f 100644 --- a/jscomp/test/bs_poly_set_test.js +++ b/jscomp/test/bs_poly_set_test.js @@ -1,8 +1,8 @@ 'use strict'; var Mt = require("./mt.js"); +var Bs_Id = require("../../lib/js/bs_Id.js"); var Bs_Set = require("../../lib/js/bs_Set.js"); -var Bs_Dict = require("../../lib/js/bs_Dict.js"); var Bs_List = require("../../lib/js/bs_List.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Caml_obj = require("../../lib/js/caml_obj.js"); @@ -26,7 +26,7 @@ function t(loc, x) { return Mt.throw_suites(test_id, suites, loc, x); } -var IntCmp = Bs_Dict.comparable(Caml_primitive.caml_int_compare); +var IntCmp = Bs_Id.comparable(Caml_primitive.caml_int_compare); var u0 = Bs_Set.ofArray(Array_data_util.range(0, 30), IntCmp); diff --git a/jscomp/test/bs_poly_set_test.ml b/jscomp/test/bs_poly_set_test.ml index 9ece6424c0..6085130118 100644 --- a/jscomp/test/bs_poly_set_test.ml +++ b/jscomp/test/bs_poly_set_test.ml @@ -7,7 +7,7 @@ module N = Bs.Set module I = Array_data_util module A = Bs.Array module IntCmp = - (val Bs.Dict.comparable (fun (x:int) y -> compare x y)) + (val Bs.Id.comparable (fun (x:int) y -> compare x y)) module L = Bs.List let () = diff --git a/lib/js/bs.js b/lib/js/bs.js index 2588aee4d0..50a1edc580 100644 --- a/lib/js/bs.js +++ b/lib/js/bs.js @@ -1,7 +1,7 @@ 'use strict'; -var Dict = 0; +var Id = 0; var $$Array = 0; @@ -27,7 +27,7 @@ var HashSet = 0; var HashMap = 0; -exports.Dict = Dict; +exports.Id = Id; exports.$$Array = $$Array; exports.SortArray = SortArray; exports.MutableQueue = MutableQueue; diff --git a/lib/js/bs_Array.js b/lib/js/bs_Array.js index 62e09bf3b7..5b14f63e14 100644 --- a/lib/js/bs_Array.js +++ b/lib/js/bs_Array.js @@ -124,6 +124,35 @@ function makeByAndShuffle(l, f) { return makeByAndShuffleU(l, Curry.__1(f)); } +function range(start, finish) { + var cut = finish - start | 0; + if (cut < 0) { + return /* int array */[]; + } else { + var arr = new Array(cut + 1 | 0); + for(var i = 0; i <= cut; ++i){ + arr[i] = start + i | 0; + } + return arr; + } +} + +function rangeBy(start, finish, step) { + var cut = finish - start | 0; + if (cut < 0 || step <= 0) { + return /* int array */[]; + } else { + var nb = (cut / step | 0) + 1 | 0; + var arr = new Array(nb); + var cur = start; + for(var i = 0 ,i_finish = nb - 1 | 0; i <= i_finish; ++i){ + arr[i] = cur; + cur = cur + step | 0; + } + return arr; + } +} + function zip(xs, ys) { var lenx = xs.length; var leny = ys.length; @@ -526,6 +555,8 @@ exports.shuffle = shuffle; exports.reverseInPlace = reverseInPlace; exports.reverse = reverse; exports.make = make; +exports.range = range; +exports.rangeBy = rangeBy; exports.makeByU = makeByU; exports.makeBy = makeBy; exports.makeByAndShuffleU = makeByAndShuffleU; diff --git a/lib/js/bs_Id.js b/lib/js/bs_Id.js new file mode 100644 index 0000000000..636adfdb7e --- /dev/null +++ b/lib/js/bs_Id.js @@ -0,0 +1,28 @@ +'use strict'; + +var Curry = require("./curry.js"); + +function comparableU(cmp) { + return /* module */[/* cmp */cmp]; +} + +function comparable(cmp) { + return comparableU(Curry.__2(cmp)); +} + +function hashableU(hash, eq) { + return /* module */[ + /* hash */hash, + /* eq */eq + ]; +} + +function hashable(hash, eq) { + return hashableU(Curry.__1(hash), Curry.__2(eq)); +} + +exports.comparableU = comparableU; +exports.comparable = comparable; +exports.hashableU = hashableU; +exports.hashable = hashable; +/* No side effect */ diff --git a/lib/js/bs_Map.js b/lib/js/bs_Map.js index 8bf6e2e0be..bfc74064d9 100644 --- a/lib/js/bs_Map.js +++ b/lib/js/bs_Map.js @@ -3,8 +3,8 @@ var Curry = require("./curry.js"); var Bs_MapDict = require("./bs_MapDict.js"); -function ofArray(data, dict) { - var cmp = dict[/* cmp */0]; +function ofArray(data, id) { + var cmp = id[/* cmp */0]; return { cmp: cmp, data: Bs_MapDict.ofArray(data, cmp) @@ -94,9 +94,9 @@ function merge(s1, s2, f) { return mergeU(s1, s2, Curry.__3(f)); } -function make(dict) { +function make(id) { return { - cmp: dict[/* cmp */0], + cmp: id[/* cmp */0], data: Bs_MapDict.empty }; } @@ -285,14 +285,14 @@ function getData(prim) { return prim.data; } -function getDict(m) { +function getId(m) { var cmp = m.cmp; return /* module */[/* cmp */cmp]; } -function packDictData(dict, data) { +function packIdData(id, data) { return { - cmp: dict[/* cmp */0], + cmp: id[/* cmp */0], data: data }; } @@ -357,7 +357,7 @@ exports.mapU = mapU; exports.map = map; exports.mapWithKeyU = mapWithKeyU; exports.mapWithKey = mapWithKey; -exports.getDict = getDict; +exports.getId = getId; exports.getData = getData; -exports.packDictData = packDictData; +exports.packIdData = packIdData; /* No side effect */ diff --git a/lib/js/bs_Range.js b/lib/js/bs_Range.js index fee0c81dcd..6fb5ea2e02 100644 --- a/lib/js/bs_Range.js +++ b/lib/js/bs_Range.js @@ -32,19 +32,27 @@ function every(s, f, p) { return everyU(s, f, Curry.__1(p)); } -function everyByU(_s, f, step, p) { - while(true) { - var s = _s; - if (s > f) { - return /* true */1; - } else if (p(s)) { - _s = s + step | 0; - continue ; - - } else { - return /* false */0; - } - }; +function everyByU(s, f, step, p) { + if (step > 0) { + var _s = s; + var f$1 = f; + var step$1 = step; + var p$1 = p; + while(true) { + var s$1 = _s; + if (s$1 > f$1) { + return /* true */1; + } else if (p$1(s$1)) { + _s = s$1 + step$1 | 0; + continue ; + + } else { + return /* false */0; + } + }; + } else { + return /* true */1; + } } function everyBy(s, f, step, p) { @@ -70,19 +78,27 @@ function some(s, f, p) { return someU(s, f, Curry.__1(p)); } -function someByU(_s, f, step, p) { - while(true) { - var s = _s; - if (s > f) { - return /* false */0; - } else if (p(s)) { - return /* true */1; - } else { - _s = s + step | 0; - continue ; - - } - }; +function someByU(s, f, step, p) { + if (step > 0) { + var _s = s; + var f$1 = f; + var step$1 = step; + var p$1 = p; + while(true) { + var s$1 = _s; + if (s$1 > f$1) { + return /* false */0; + } else if (p$1(s$1)) { + return /* true */1; + } else { + _s = s$1 + step$1 | 0; + continue ; + + } + }; + } else { + return /* false */0; + } } function someBy(s, f, step, p) {