From fc13e6ffc0e980dabb7e7cccd80aca6e2f92a481 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sat, 10 Feb 2018 14:32:51 +0800 Subject: [PATCH 1/2] full test coverage for lists, fix one minor bug --- docs/api/Bs.html | 310 +- docs/api/Dom.Storage.html | 45 +- docs/api/Dom.html | 49 +- docs/api/Dom_storage.html | 45 +- docs/api/Js.Array.html | 45 +- docs/api/Js.Boolean.html | 45 +- docs/api/Js.Date.html | 45 +- docs/api/Js.Dict.html | 45 +- docs/api/Js.Exn.html | 45 +- docs/api/Js.Float.html | 45 +- docs/api/Js.Global.html | 117 +- docs/api/Js.Int.html | 49 +- docs/api/Js.Json.html | 85 +- docs/api/Js.List.html | 45 +- docs/api/Js.Math.html | 53 +- docs/api/Js.Null.html | 52 +- docs/api/Js.Null_undefined.html | 58 +- docs/api/Js.Nullable.html | 58 +- docs/api/Js.Obj.html | 45 +- docs/api/Js.Option.html | 45 +- docs/api/Js.Promise.html | 45 +- docs/api/Js.Re.html | 52 +- docs/api/Js.Result.html | 45 +- docs/api/Js.String.html | 45 +- docs/api/Js.Typed_array.html | 45 +- docs/api/Js.Types.html | 45 +- docs/api/Js.Undefined.html | 55 +- docs/api/Js.Vector.html | 51 +- docs/api/Js.html | 55 +- docs/api/Js_array.html | 45 +- docs/api/Js_boolean.html | 45 +- docs/api/Js_cast.html | 49 +- docs/api/Js_date.html | 49 +- docs/api/Js_dict.html | 45 +- docs/api/Js_exn.html | 45 +- docs/api/Js_float.html | 45 +- docs/api/Js_global.html | 120 +- docs/api/Js_int.html | 49 +- docs/api/Js_int64.html | 45 +- docs/api/Js_internal.html | 45 +- docs/api/Js_json.html | 85 +- docs/api/Js_list.html | 49 +- docs/api/Js_math.html | 57 +- docs/api/Js_nativeint.html | 45 +- docs/api/Js_null.html | 52 +- docs/api/Js_null_undefined.html | 58 +- docs/api/Js_obj.html | 45 +- docs/api/Js_option.html | 45 +- docs/api/Js_primitive.html | 45 +- docs/api/Js_promise.html | 45 +- docs/api/Js_re.html | 52 +- docs/api/Js_result.html | 45 +- docs/api/Js_string.html | 45 +- docs/api/Js_typed_array.ArrayBuffer.html | 45 +- docs/api/Js_typed_array.DataView.html | 45 +- docs/api/Js_typed_array.Float32Array.html | 45 +- docs/api/Js_typed_array.Float32_array.html | 45 +- docs/api/Js_typed_array.Float64Array.html | 45 +- docs/api/Js_typed_array.Float64_array.html | 45 +- docs/api/Js_typed_array.Int16Array.html | 45 +- docs/api/Js_typed_array.Int32Array.html | 45 +- docs/api/Js_typed_array.Int32_array.html | 45 +- docs/api/Js_typed_array.Int8Array.html | 45 +- docs/api/Js_typed_array.S.html | 45 +- docs/api/Js_typed_array.Type.html | 45 +- docs/api/Js_typed_array.Uint16Array.html | 45 +- docs/api/Js_typed_array.Uint32Array.html | 45 +- docs/api/Js_typed_array.Uint8Array.html | 45 +- .../api/Js_typed_array.Uint8ClampedArray.html | 45 +- docs/api/Js_typed_array.html | 45 +- docs/api/Js_types.html | 45 +- docs/api/Js_undefined.html | 55 +- docs/api/Js_unsafe.html | 45 +- docs/api/Js_vector.html | 46 +- docs/api/Node.Buffer.html | 45 +- docs/api/Node.Child_process.html | 45 +- docs/api/Node.Fs.html | 45 +- docs/api/Node.Module.html | 45 +- docs/api/Node.Path.html | 45 +- docs/api/Node.Process.html | 45 +- docs/api/Node.html | 45 +- docs/api/Node_buffer.html | 45 +- docs/api/Node_child_process.html | 45 +- docs/api/Node_fs.Watch.html | 45 +- docs/api/Node_fs.html | 45 +- docs/api/Node_module.html | 45 +- docs/api/Node_path.html | 45 +- docs/api/Node_process.html | 45 +- docs/api/index.html | 22 +- docs/api/index_attributes.html | 45 +- docs/api/index_class_types.html | 45 +- docs/api/index_classes.html | 45 +- docs/api/index_exceptions.html | 45 +- docs/api/index_extensions.html | 45 +- docs/api/index_methods.html | 45 +- docs/api/index_module_types.html | 59 +- docs/api/index_modules.html | 1212 +- docs/api/index_types.html | 528 +- docs/api/index_values.html | 10198 ++++++++++++++-- docs/api/type_Js.html | 17 +- docs/api/type_Js_null.html | 7 +- docs/api/type_Js_null_undefined.html | 1 - docs/api/type_Js_undefined.html | 6 +- docs/api/type_Js_vector.html | 1 - jscomp/others/belt_List.ml | 4 +- jscomp/test/bs_list_test.js | 505 +- jscomp/test/bs_list_test.ml | 76 +- lib/js/belt_List.js | 16 +- 108 files changed, 15682 insertions(+), 1840 deletions(-) diff --git a/docs/api/Bs.html b/docs/api/Bs.html index 02bac4d443..9e40030764 100644 --- a/docs/api/Bs.html +++ b/docs/api/Bs.html @@ -7,18 +7,56 @@ - + Bs

Module Bs

module Bs: sig .. end
- Placeholder for BuckleScript data structures
+ A stdlib shipped with BuckleScript +

+ + This stdlib is still in beta status, but we encourage you to try it out and + provide feedback. +

+ + Motivation +

+ + The motivation of creating such library is to provide BuckleScript users a + better end-to-end user experience, since the original OCaml stdlib was not + writte with JS platform in mind, below are a list of areas this lib aims to + improve:

    +
  1. 1. Consistency in name convention: camlCase, and arguments order
  2. +
  3. 2. Exception thrown functions are all suffixed with Exn, e.g, getExn
  4. +
  5. 3. Beter peformance and smaller code size running on JS platform
  6. +
+ +

+ + Name Convention +

+ + For higher order functions, it will be suffixed U if it takes uncurried + callback. +

+ +

      val forEach : 'a t -> ('a -> unit) -> unit
+      val forEachU : 'a t -> ('a -> unit [@bs]) -> unit
+    
+

+ + In general, uncurried version will be faster, but it is less familiar to + people who have a background in functional programming. +

+ + A special encoding for collection safety +

+ + When we create a collection library for a custom data type, take Set for + example, suppose its element type is a pair of ints, + it needs a custom compare function. However, the Set could not + just be typed as Set.t (int * int) , + its customized compare function needs to be + manifested in the signature, otherwise, if the user create another + customized compare function, and the two collection would mix which + would result in runtime error. +

+ + The original OCaml stdlib solved the problem using functor which is a big + closure in runtime; it makes dead code elimination much harder. + We introduced a phantom type to solve the problem +

+ +

      type t = int * int 
+      module I0 =
+        (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 ~id:(module I0)
+    module I1 =
+      (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 ~id:(module I1)
+    
+

+ + Here the compiler would infer s0 and s1 having different type so that + it would not mix. +

+ +

      val s0 : ((int * int), I0.identity) t
+      val s1 : ((int * int), I1.identity) t
+    
+

+ + I0.identity and I1.identity are not the same using our encoding scheme. +

+ + Collection Hierachy +

+ + In general, we provide a generic collection module, but also create specialized + modules for commonly used data type, take Bs.Set for example +

+ +

      Bs.Set
+      Bs.Set.Int
+      Bs.Set.String
+    
+

+ + The specialized module Bs.Set.Int, Bs.Set.String is in general more + efficient. +

+ + Currently, both Bs_Set and Bs.Set are accessible to users for some + technical rasons, + we strongly recommend users stick to qualified import, Bs.Sort, we may hide + the internal, i.e, Bs_Set in the future

@@ -67,16 +211,158 @@

Module Bs


-
module Dyn: Bs_dyn
+
module Id: Bs_Id
+
+ Bs.Id +

+ + Provide utiliites to create identified comparators or hashes for + data structures used below. +

+ + It create a unique identifer per module of + functions so that different data structures with slightly different + comparison functions won't mix
+ +

+
+
module Array: Bs_Array
+
+ Bs.Array +

+ + mutable array: Utililites functions
+ +

+
+
module SortArray: Bs_SortArray
+
+ Bs.SortArray +

+ + The toplevel provides some generic sort related utililties. +

+ + It also has two specialized inner modules + Bs.SortArray.Int and Bs.SortArray.String
+ +

+
+
module MutableQueue: Bs_MutableQueue
+
+ Bs.MutableQueue +

+ + An FIFO(first in first out) queue data structure
+ +

+
+
module MutableStack: Bs_MutableStack
+
+ Bs.MutableStack +

+ + An FILO(first in last out) stack data structure
+ +

+
+
module List: Bs_List
+
+ Bs.List +

+ + Utilities for List data type
+ +

+
+
module Range: Bs_Range
+
+ Bs.Range +

+ + Utilities for a closed range (from, start)
+ +

+
+
module Set: Bs_Set
- /
+ Bs.Set +

+ + The toplevel provides generic immutable set operations. +

+ + It also has three specialized inner modules + Bs.Set.Int and Bs.Set.String + Bs.Set.Dict: This module separate date from function + which is more verbbose but slightly more efficient
+ +

+
+
module Map: Bs_Map
+
+ Bs.Map, +

+ + The toplevel provides generic immutable map operations. +

+ + It also has three specialized inner modules + Bs.Map.Int and Bs.Map.String + Bs.Map.Dict: This module separate date from function + which is more verbbose but slightly more efficient

-
module Dyn_lib: Bs_dyn_lib
+
module MutableSet: Bs_MutableSet
- + Bs.MutableSet +

+ + The toplevel provides generic mutable set operations. +

+ + It also has two specialized inner modules + Bs.MutableSet.Int and Bs.MutableSet.String
+ +

+
+
module MutableMap: Bs_MutableMap
+
+ Bs.MutableMap +

+ + The toplevel provides generic mutable map operations. +

+ + It also has two specialized inner modules + Bs.MutableMap.Int and Bs.MutableMap.String
+ +

+
+
module HashSet: Bs_HashSet
+
+ Bs.HashSet +

+ + The toplevel provides generic mutable hash set operations. +

+ + It also has two specialized inner modules + Bs.HashSet.Int and Bs.HashSet.String
+ +

+
+
module HashMap: Bs_HashMap
+
+ Bs.HashMap +

+ + The toplevel provides generic mutable hash map operations. +

+ + It also has two specialized inner modules + Bs.HashMap.Int and Bs.HashMap.String
+

-

-/
- \ No newline at end of file +
\ No newline at end of file diff --git a/docs/api/Dom.Storage.html b/docs/api/Dom.Storage.html index d4387e5a6e..84a7a3c939 100644 --- a/docs/api/Dom.Storage.html +++ b/docs/api/Dom.Storage.html @@ -10,15 +10,53 @@ Dom.Storage -