diff --git a/jscomp/build_tests/super_errors/expected/modules2.res.expected b/jscomp/build_tests/super_errors/expected/modules2.res.expected index b1b5ad1b34..633a4a99cd 100644 --- a/jscomp/build_tests/super_errors/expected/modules2.res.expected +++ b/jscomp/build_tests/super_errors/expected/modules2.res.expected @@ -1,8 +1,8 @@ We've found a bug for you! - /.../fixtures/modules2.res:1:9-14 + /.../fixtures/modules2.res:1:9-19 - 1 │ let b = List.b + 1 │ let b = Belt.List.b 2 │ - The value b can't be found in List \ No newline at end of file + The value b can't be found in Belt.List \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/primitives7.res.expected b/jscomp/build_tests/super_errors/expected/primitives7.res.expected index 0f7375f708..95aa2472c5 100644 --- a/jscomp/build_tests/super_errors/expected/primitives7.res.expected +++ b/jscomp/build_tests/super_errors/expected/primitives7.res.expected @@ -1,17 +1,20 @@ We've found a bug for you! - /.../fixtures/primitives7.res:3:24 + /.../fixtures/primitives7.res:3:23 1 │ /* Wanted list(float), found list(int) */ 2 │ let a = list{1, 2, 3} - 3 │ List.map(n => n +. 2., a) + 3 │ a->Belt.List.map(n => n +. 2.) 4 │ - This has type: list - But this function argument is expecting: list - - The incompatible parts: - int vs float + This has type: int + But it's being used with the +. operator, which works on: float + + Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two. + + Possible solutions: + - Ensure all values in this calculation has the type float. You can convert between floats and ints via Belt.Float.toInt and Belt.Int.fromFloat. + - Change the operator to +, which works on int You can convert int to float with Belt.Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/modules2.res b/jscomp/build_tests/super_errors/fixtures/modules2.res index 9f17e8b2b9..336b4a1f1a 100644 --- a/jscomp/build_tests/super_errors/fixtures/modules2.res +++ b/jscomp/build_tests/super_errors/fixtures/modules2.res @@ -1 +1 @@ -let b = List.b +let b = Belt.List.b diff --git a/jscomp/build_tests/super_errors/fixtures/primitives7.res b/jscomp/build_tests/super_errors/fixtures/primitives7.res index d456521d78..1df613d45f 100644 --- a/jscomp/build_tests/super_errors/fixtures/primitives7.res +++ b/jscomp/build_tests/super_errors/fixtures/primitives7.res @@ -1,3 +1,3 @@ /* Wanted list(float), found list(int) */ let a = list{1, 2, 3} -List.map(n => n +. 2., a) +a->Belt.List.map(n => n +. 2.) diff --git a/jscomp/stdlib-406/complex.res b/jscomp/stdlib-406/complex.res deleted file mode 100644 index 4b0561011f..0000000000 --- a/jscomp/stdlib-406/complex.res +++ /dev/null @@ -1,112 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2002 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/* Complex numbers */ - -type t = {re: float, im: float} - -let zero = {re: 0.0, im: 0.0} -let one = {re: 1.0, im: 0.0} -let i = {re: 0.0, im: 1.0} - -let add = (x, y) => {re: x.re +. y.re, im: x.im +. y.im} - -let sub = (x, y) => {re: x.re -. y.re, im: x.im -. y.im} - -let neg = x => {re: -.x.re, im: -.x.im} - -let conj = x => {re: x.re, im: -.x.im} - -let mul = (x, y) => { - re: x.re *. y.re -. x.im *. y.im, - im: x.re *. y.im +. x.im *. y.re, -} - -let div = (x, y) => - if abs_float(y.re) >= abs_float(y.im) { - let r = y.im /. y.re - let d = y.re +. r *. y.im - { - re: (x.re +. r *. x.im) /. d, - im: (x.im -. r *. x.re) /. d, - } - } else { - let r = y.re /. y.im - let d = y.im +. r *. y.re - { - re: (r *. x.re +. x.im) /. d, - im: (r *. x.im -. x.re) /. d, - } - } - -let inv = x => div(one, x) - -let norm2 = x => x.re *. x.re +. x.im *. x.im - -let norm = x => { - /* Watch out for overflow in computing re^2 + im^2 */ - let r = abs_float(x.re) - and i = abs_float(x.im) - if r == 0.0 { - i - } else if i == 0.0 { - r - } else if r >= i { - let q = i /. r - r *. sqrt(1.0 +. q *. q) - } else { - let q = r /. i - i *. sqrt(1.0 +. q *. q) - } -} - -let arg = x => atan2(x.im, x.re) - -let polar = (n, a) => {re: cos(a) *. n, im: sin(a) *. n} - -let sqrt = x => - if x.re == 0.0 && x.im == 0.0 { - {re: 0.0, im: 0.0} - } else { - let r = abs_float(x.re) and i = abs_float(x.im) - let w = if r >= i { - let q = i /. r - sqrt(r) *. sqrt(0.5 *. (1.0 +. sqrt(1.0 +. q *. q))) - } else { - let q = r /. i - sqrt(i) *. sqrt(0.5 *. (q +. sqrt(1.0 +. q *. q))) - } - if x.re >= 0.0 { - {re: w, im: 0.5 *. x.im /. w} - } else { - { - re: 0.5 *. i /. w, - im: if x.im >= 0.0 { - w - } else { - -.w - }, - } - } - } - -let exp = x => { - let e = exp(x.re) - {re: e *. cos(x.im), im: e *. sin(x.im)} -} - -let log = x => {re: log(norm(x)), im: atan2(x.im, x.re)} - -let pow = (x, y) => exp(mul(y, log(x))) diff --git a/jscomp/stdlib-406/complex.resi b/jscomp/stdlib-406/complex.resi deleted file mode 100644 index bacdc477d5..0000000000 --- a/jscomp/stdlib-406/complex.resi +++ /dev/null @@ -1,86 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2002 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** Complex numbers. - - This module provides arithmetic operations on complex numbers. - Complex numbers are represented by their real and imaginary parts - (cartesian representation). Each part is represented by a - double-precision floating-point number (type [float]). */ - -/** The type of complex numbers. [re] is the real part and [im] the - imaginary part. */ -type t = {re: float, im: float} - -/** The complex number [0]. */ -let zero: t - -/** The complex number [1]. */ -let one: t - -/** The complex number [i]. */ -let i: t - -/** Unary negation. */ -let neg: t => t - -/** Conjugate: given the complex [x + i.y], returns [x - i.y]. */ -let conj: t => t - -/** Addition */ -let add: (t, t) => t - -/** Subtraction */ -let sub: (t, t) => t - -/** Multiplication */ -let mul: (t, t) => t - -/** Multiplicative inverse ([1/z]). */ -let inv: t => t - -/** Division */ -let div: (t, t) => t - -/** Square root. The result [x + i.y] is such that [x > 0] or - [x = 0] and [y >= 0]. - This function has a discontinuity along the negative real axis. */ -let sqrt: t => t - -/** Norm squared: given [x + i.y], returns [x^2 + y^2]. */ -let norm2: t => float - -/** Norm: given [x + i.y], returns [sqrt(x^2 + y^2)]. */ -let norm: t => float - -/** Argument. The argument of a complex number is the angle - in the complex plane between the positive real axis and a line - passing through zero and the number. This angle ranges from - [-pi] to [pi]. This function has a discontinuity along the - negative real axis. */ -let arg: t => float - -/** [polar norm arg] returns the complex having norm [norm] - and argument [arg]. */ -let polar: (float, float) => t - -/** Exponentiation. [exp z] returns [e] to the [z] power. */ -let exp: t => t - -/** Natural logarithm (in base [e]). */ -let log: t => t - -/** Power function. [pow z1 z2] returns [z1] to the [z2] power. */ -let pow: (t, t) => t diff --git a/jscomp/stdlib-406/list.res b/jscomp/stdlib-406/list.res deleted file mode 100644 index 4aa190c89f..0000000000 --- a/jscomp/stdlib-406/list.res +++ /dev/null @@ -1,749 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/* List operations */ - -let rec length_aux = (len, param) => - switch param { - | list{} => len - | list{_, ...l} => length_aux(len + 1, l) - } - -let length = l => length_aux(0, l) - -let cons = (a, l) => list{a, ...l} - -let hd = param => - switch param { - | list{} => failwith("hd") - | list{a, ..._} => a - } - -let tl = param => - switch param { - | list{} => failwith("tl") - | list{_, ...l} => l - } - -let nth = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => failwith("nth") - | list{a, ...l} => - if n == 0 { - a - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let nth_opt = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => None - | list{a, ...l} => - if n == 0 { - Some(a) - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let append = \"@" - -let rec rev_append = (l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => rev_append(l, list{a, ...l2}) - } - -let rev = l => rev_append(l, list{}) - -let rec init_tailrec_aux = (acc, i, n, f) => - if i >= n { - acc - } else { - init_tailrec_aux(list{f(i), ...acc}, i + 1, n, f) - } - -let rec init_aux = (i, n, f) => - if i >= n { - list{} - } else { - let r = f(i) - list{r, ...init_aux(i + 1, n, f)} - } - -let init = (len, f) => - if len < 0 { - invalid_arg("List.init") - } else if len > 10_000 { - rev(init_tailrec_aux(list{}, 0, len, f)) - } else { - init_aux(0, len, f) - } - -let rec flatten = param => - switch param { - | list{} => list{} - | list{l, ...r} => \"@"(l, flatten(r)) - } - -let concat = flatten - -let rec map = (f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(a) - list{r, ...map(f, l)} - } - -let rec mapi = (i, f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(i, a) - list{r, ...mapi(i + 1, f, l)} - } - -let mapi = (f, l) => mapi(0, f, l) - -let rev_map = (f, l) => { - let rec rmap_f = (accu, param) => - switch param { - | list{} => accu - | list{a, ...l} => rmap_f(list{f(a), ...accu}, l) - } - - rmap_f(list{}, l) -} - -let rec iter = (f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(a) - iter(f, l) - } - -let rec iteri = (i, f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(i, a) - iteri(i + 1, f, l) - } - -let iteri = (f, l) => iteri(0, f, l) - -let rec fold_left = (f, accu, l) => - switch l { - | list{} => accu - | list{a, ...l} => fold_left(f, f(accu, a), l) - } - -let rec fold_right = (f, l, accu) => - switch l { - | list{} => accu - | list{a, ...l} => f(a, fold_right(f, l, accu)) - } - -let rec map2 = (f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => - let r = f(a1, a2) - list{r, ...map2(f, l1, l2)} - | (_, _) => invalid_arg("List.map2") - } - -let rev_map2 = (f, l1, l2) => { - let rec rmap2_f = (accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => rmap2_f(list{f(a1, a2), ...accu}, l1, l2) - | (_, _) => invalid_arg("List.rev_map2") - } - - rmap2_f(list{}, l1, l2) -} - -let rec iter2 = (f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => () - | (list{a1, ...l1}, list{a2, ...l2}) => - f(a1, a2) - iter2(f, l1, l2) - | (_, _) => invalid_arg("List.iter2") - } - -let rec fold_left2 = (f, accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => fold_left2(f, f(accu, a1, a2), l1, l2) - | (_, _) => invalid_arg("List.fold_left2") - } - -let rec fold_right2 = (f, l1, l2, accu) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => f(a1, a2, fold_right2(f, l1, l2, accu)) - | (_, _) => invalid_arg("List.fold_right2") - } - -let rec for_all = (p, param) => - switch param { - | list{} => true - | list{a, ...l} => p(a) && for_all(p, l) - } - -let rec exists = (p, param) => - switch param { - | list{} => false - | list{a, ...l} => p(a) || exists(p, l) - } - -let rec for_all2 = (p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && for_all2(p, l1, l2) - | (_, _) => invalid_arg("List.for_all2") - } - -let rec exists2 = (p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => false - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || exists2(p, l1, l2) - | (_, _) => invalid_arg("List.exists2") - } - -let rec mem = (x, param) => - switch param { - | list{} => false - | list{a, ...l} => compare(a, x) == 0 || mem(x, l) - } - -let rec memq = (x, param) => - switch param { - | list{} => false - | list{a, ...l} => a === x || memq(x, l) - } - -let rec assoc = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if compare(a, x) == 0 { - b - } else { - assoc(x, l) - } - } - -let rec assoc_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if compare(a, x) == 0 { - Some(b) - } else { - assoc_opt(x, l) - } - } - -let rec assq = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if a === x { - b - } else { - assq(x, l) - } - } - -let rec assq_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if a === x { - Some(b) - } else { - assq_opt(x, l) - } - } - -let rec mem_assoc = (x, param) => - switch param { - | list{} => false - | list{(a, _), ...l} => compare(a, x) == 0 || mem_assoc(x, l) - } - -let rec mem_assq = (x, param) => - switch param { - | list{} => false - | list{(a, _), ...l} => a === x || mem_assq(x, l) - } - -let rec remove_assoc = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if compare(a, x) == 0 { - l - } else { - list{pair, ...remove_assoc(x, l)} - } - } - -let rec remove_assq = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if a === x { - l - } else { - list{pair, ...remove_assq(x, l)} - } - } - -let rec find = (p, param) => - switch param { - | list{} => raise(Not_found) - | list{x, ...l} => - if p(x) { - x - } else { - find(p, l) - } - } - -let rec find_opt = (p, param) => - switch param { - | list{} => None - | list{x, ...l} => - if p(x) { - Some(x) - } else { - find_opt(p, l) - } - } - -let find_all = (p, l) => { - let rec find = (accu, param) => - switch param { - | list{} => rev(accu) - | list{x, ...l} => - if p(x) { - find(list{x, ...accu}, l) - } else { - find(accu, l) - } - } - find(list{}, l) -} - -let filter = find_all - -let partition = (p, l) => { - let rec part = (yes, no, param) => - switch param { - | list{} => (rev(yes), rev(no)) - | list{x, ...l} => - if p(x) { - part(list{x, ...yes}, no, l) - } else { - part(yes, list{x, ...no}, l) - } - } - part(list{}, list{}, l) -} - -let rec split = param => - switch param { - | list{} => (list{}, list{}) - | list{(x, y), ...l} => - let (rx, ry) = split(l) - (list{x, ...rx}, list{y, ...ry}) - } - -let rec combine = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => list{(a1, a2), ...combine(l1, l2)} - | (_, _) => invalid_arg("List.combine") - } - -/* sorting */ - -let rec merge = (cmp, l1, l2) => - switch (l1, l2) { - | (list{}, l2) => l2 - | (l1, list{}) => l1 - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - list{h1, ...merge(cmp, t1, l2)} - } else { - list{h2, ...merge(cmp, l1, t2)} - } - } - -let rec chop = (k, l) => - if k == 0 { - l - } else { - switch l { - | list{_, ...t} => chop(k - 1, t) - | _ => assert(false) - } - } - -let stable_sort = (cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) <= 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) <= 0 { - if cmp(x2, x3) <= 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) <= 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) <= 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) <= 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) > 0 { - if cmp(x2, x3) > 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) > 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let sort = stable_sort -let fast_sort = stable_sort - -/* Note: on a list of length between about 100000 (depending on the minor - heap size and the type of the list) and Sys.max_array_size, it is - actually faster to use the following, but it might also use more memory - because the argument list cannot be deallocated incrementally. - - Also, there seems to be a bug in this code or in the - implementation of obj_truncate. - -external obj_truncate : 'a array -> int -> unit = "caml_obj_truncate" - -let array_to_list_in_place a = - let l = Array.length a in - let rec loop accu n p = - if p <= 0 then accu else begin - if p = n then begin - obj_truncate a p; - loop (a.(p-1) :: accu) (n-1000) (p-1) - end else begin - loop (a.(p-1) :: accu) n (p-1) - end - end - in - loop [] (l-1000) l - - -let stable_sort cmp l = - let a = Array.of_list l in - Array.stable_sort cmp a; - array_to_list_in_place a - -*/ - -/* sorting + removing duplicates */ - -let sort_uniq = (cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge(t1, t2, list{h1, ...accu}) - } else if c < 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge_rev(t1, t2, list{h1, ...accu}) - } else if c > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c < 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c < 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c < 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c > 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c > 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let rec compare_lengths = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => 0 - | (list{}, _) => -1 - | (_, list{}) => 1 - | (list{_, ...l1}, list{_, ...l2}) => compare_lengths(l1, l2) - } - -let rec compare_length_with = (l, n) => - switch l { - | list{} => - if n == 0 { - 0 - } else if n > 0 { - -1 - } else { - 1 - } - | list{_, ...l} => - if n <= 0 { - 1 - } else { - compare_length_with(l, n - 1) - } - } diff --git a/jscomp/stdlib-406/list.resi b/jscomp/stdlib-406/list.resi deleted file mode 100644 index 27e82bbdf8..0000000000 --- a/jscomp/stdlib-406/list.resi +++ /dev/null @@ -1,333 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** List operations. - - Some functions are flagged as not tail-recursive. A tail-recursive - function uses constant stack space, while a non-tail-recursive function - uses stack space proportional to the length of its list argument, which - can be a problem with very long lists. When the function takes several - list arguments, an approximate formula giving stack usage (in some - unspecified constant unit) is shown in parentheses. - - The above considerations can usually be ignored if your lists are not - longer than about 10000 elements. -*/ - -/** Return the length (number of elements) of the given list. */ -let length: list<'a> => int - -/** Compare the lengths of two lists. [compare_lengths l1 l2] is - equivalent to [compare (length l1) (length l2)], except that - the computation stops after itering on the shortest list. - @since 4.05.0 - */ -let compare_lengths: (list<'a>, list<'b>) => int - -/** Compare the length of a list to an integer. [compare_length_with l n] is - equivalent to [compare (length l) n], except that - the computation stops after at most [n] iterations on the list. - @since 4.05.0 -*/ -let compare_length_with: (list<'a>, int) => int - -/** [cons x xs] is [x :: xs] - @since 4.03.0 -*/ -let cons: ('a, list<'a>) => list<'a> - -/** Return the first element of the given list. Raise - [Failure "hd"] if the list is empty. */ -let hd: list<'a> => 'a - -/** Return the given list without its first element. Raise - [Failure "tl"] if the list is empty. */ -let tl: list<'a> => list<'a> - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Raise [Failure "nth"] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. */ -let nth: (list<'a>, int) => 'a - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Return [None] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. - @since 4.05 -*/ -let nth_opt: (list<'a>, int) => option<'a> - -/** List reversal. */ -let rev: list<'a> => list<'a> - -/** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. - - @raise Invalid_argument if len < 0. - @since 4.06.0 -*/ -let init: (int, int => 'a) => list<'a> - -/** Concatenate two lists. Same as the infix operator [@]. - Not tail-recursive (length of the first argument). */ -let append: (list<'a>, list<'a>) => list<'a> - -/** [List.rev_append l1 l2] reverses [l1] and concatenates it to [l2]. - This is equivalent to {!List.rev}[ l1 @ l2], but [rev_append] is - tail-recursive and more efficient. */ -let rev_append: (list<'a>, list<'a>) => list<'a> - -/** Concatenate a list of lists. The elements of the argument are all - concatenated together (in the same order) to give the result. - Not tail-recursive - (length of the argument + length of the longest sub-list). */ -let concat: list> => list<'a> - -/** An alias for [concat]. */ -let flatten: list> => list<'a> - -/* {1 Iterators} */ - -/** [List.iter f [a1; ...; an]] applies function [f] in turn to - [a1; ...; an]. It is equivalent to - [begin f a1; f a2; ...; f an; () end]. */ -let iter: ('a => unit, list<'a>) => unit - -/** Same as {!List.iter}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -let iteri: ((int, 'a) => unit, list<'a>) => unit - -/** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], - and builds the list [[f a1; ...; f an]] - with the results returned by [f]. Not tail-recursive. */ -let map: ('a => 'b, list<'a>) => list<'b> - -/** Same as {!List.map}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. Not tail-recursive. - @since 4.00.0 -*/ -let mapi: ((int, 'a) => 'b, list<'a>) => list<'b> - -/** [List.rev_map f l] gives the same result as - {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and - more efficient. */ -let rev_map: ('a => 'b, list<'a>) => list<'b> - -/** [List.fold_left f a [b1; ...; bn]] is - [f (... (f (f a b1) b2) ...) bn]. */ -let fold_left: (('a, 'b) => 'a, 'a, list<'b>) => 'a - -/** [List.fold_right f [a1; ...; an] b] is - [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. */ -let fold_right: (('a, 'b) => 'b, list<'a>, 'b) => 'b - -/* {1 Iterators on two lists} */ - -/** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn - [f a1 b1; ...; f an bn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let iter2: (('a, 'b) => unit, list<'a>, list<'b>) => unit - -/** [List.map2 f [a1; ...; an] [b1; ...; bn]] is - [[f a1 b1; ...; f an bn]]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.rev_map2 f l1 l2] gives the same result as - {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and - more efficient. */ -let rev_map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is - [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let fold_left2: (('a, 'b, 'c) => 'a, 'a, list<'b>, list<'c>) => 'a - -/** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is - [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let fold_right2: (('a, 'b, 'c) => 'c, list<'a>, list<'b>, 'c) => 'c - -/* {1 List scanning} */ - -/** [for_all p [a1; ...; an]] checks if all elements of the list - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. */ -let for_all: ('a => bool, list<'a>) => bool - -/** [exists p [a1; ...; an]] checks if at least one element of - the list satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. */ -let exists: ('a => bool, list<'a>) => bool - -/** Same as {!List.for_all}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let for_all2: (('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** Same as {!List.exists}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let exists2: (('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** [mem a l] is true if and only if [a] is equal - to an element of [l]. */ -let mem: ('a, list<'a>) => bool - -/** Same as {!List.mem}, but uses physical equality instead of structural - equality to compare list elements. */ -let memq: ('a, list<'a>) => bool - -/* {1 List searching} */ - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Raise [Not_found] if there is no value that satisfies [p] in the - list [l]. */ -let find: ('a => bool, list<'a>) => 'a - -/** [find_opt p l] returns the first element of the list [l] that - satisfies the predicate [p], or [None] if there is no value that - satisfies [p] in the list [l]. - @since 4.05 */ -let find_opt: ('a => bool, list<'a>) => option<'a> - -/** [filter p l] returns all the elements of the list [l] - that satisfy the predicate [p]. The order of the elements - in the input list is preserved. */ -let filter: ('a => bool, list<'a>) => list<'a> - -/** [find_all] is another name for {!List.filter}. */ -let find_all: ('a => bool, list<'a>) => list<'a> - -/** [partition p l] returns a pair of lists [(l1, l2)], where - [l1] is the list of all the elements of [l] that - satisfy the predicate [p], and [l2] is the list of all the - elements of [l] that do not satisfy [p]. - The order of the elements in the input list is preserved. */ -let partition: ('a => bool, list<'a>) => (list<'a>, list<'a>) - -/* {1 Association lists} */ - -/** [assoc a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Raise [Not_found] if there is no value associated with [a] in the - list [l]. */ -let assoc: ('a, list<('a, 'b)>) => 'b - -/** [assoc_opt a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc_opt a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Returns [None] if there is no value associated with [a] in the - list [l]. - @since 4.05 */ -let assoc_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but uses physical equality instead of structural - equality to compare keys. */ -let assq: ('a, list<('a, 'b)>) => 'b - -/** Same as {!List.assoc_opt}, but uses physical equality instead of structural - equality to compare keys. - @since 4.05 */ -let assq_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but simply return true if a binding exists, - and false if no bindings exist for the given key. */ -let mem_assoc: ('a, list<('a, 'b)>) => bool - -/** Same as {!List.mem_assoc}, but uses physical equality instead of - structural equality to compare keys. */ -let mem_assq: ('a, list<('a, 'b)>) => bool - -/** [remove_assoc a l] returns the list of - pairs [l] without the first pair with key [a], if any. - Not tail-recursive. */ -let remove_assoc: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/** Same as {!List.remove_assoc}, but uses physical equality instead - of structural equality to compare keys. Not tail-recursive. */ -let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/* {1 Lists of pairs} */ - -/** Transform a list of pairs into a pair of lists: - [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. - Not tail-recursive. -*/ -let split: list<('a, 'b)> => (list<'a>, list<'b>) - -/** Transform a pair of lists into a list of pairs: - [combine [a1; ...; an] [b1; ...; bn]] is - [[(a1,b1); ...; (an,bn)]]. - Raise [Invalid_argument] if the two lists - have different lengths. Not tail-recursive. */ -let combine: (list<'a>, list<'b>) => list<('a, 'b)> - -/* {1 Sorting} */ - -/** Sort a list in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see Array.sort for - a complete specification). For example, - {!Pervasives.compare} is a suitable comparison function. - The resulting list is sorted in increasing order. - [List.sort] is guaranteed to run in constant heap space - (in addition to the size of the result list) and logarithmic - stack space. - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but the sorting algorithm is guaranteed to - be stable (i.e. elements that compare equal are kept in their - original order) . - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let stable_sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort} or {!List.stable_sort}, whichever is faster - on typical input. */ -let fast_sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but also remove duplicates. - @since 4.02.0 */ -let sort_uniq: (('a, 'a) => int, list<'a>) => list<'a> - -/** Merge two lists: - Assuming that [l1] and [l2] are sorted according to the - comparison function [cmp], [merge cmp l1 l2] will return a - sorted list containing all the elements of [l1] and [l2]. - If several elements compare equal, the elements of [l1] will be - before the elements of [l2]. - Not tail-recursive (sum of the lengths of the arguments). -*/ -let merge: (('a, 'a) => int, list<'a>, list<'a>) => list<'a> diff --git a/jscomp/stdlib-406/listLabels.res b/jscomp/stdlib-406/listLabels.res deleted file mode 100644 index d08db5ee32..0000000000 --- a/jscomp/stdlib-406/listLabels.res +++ /dev/null @@ -1,748 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/* List operations */ - -let rec length_aux = (len, param) => - switch param { - | list{} => len - | list{_, ...l} => length_aux(len + 1, l) - } - -let length = l => length_aux(0, l) - -let cons = (a, l) => list{a, ...l} - -let hd = param => - switch param { - | list{} => failwith("hd") - | list{a, ..._} => a - } - -let tl = param => - switch param { - | list{} => failwith("tl") - | list{_, ...l} => l - } - -let nth = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => failwith("nth") - | list{a, ...l} => - if n == 0 { - a - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let nth_opt = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => None - | list{a, ...l} => - if n == 0 { - Some(a) - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let append = \"@" - -let rec rev_append = (l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => rev_append(l, list{a, ...l2}) - } - -let rev = l => rev_append(l, list{}) - -let rec init_tailrec_aux = (acc, i, n, f) => - if i >= n { - acc - } else { - init_tailrec_aux(list{f(i), ...acc}, i + 1, n, f) - } - -let rec init_aux = (i, n, f) => - if i >= n { - list{} - } else { - let r = f(i) - list{r, ...init_aux(i + 1, n, f)} - } - -let init = (~len, ~f) => - if len < 0 { - invalid_arg("List.init") - } else if len > 10_000 { - rev(init_tailrec_aux(list{}, 0, len, f)) - } else { - init_aux(0, len, f) - } - -let rec flatten = param => - switch param { - | list{} => list{} - | list{l, ...r} => \"@"(l, flatten(r)) - } - -let concat = flatten - -let rec map = (~f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(a) - list{r, ...map(~f, l)} - } - -let rec mapi = (i, f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(i, a) - list{r, ...mapi(i + 1, f, l)} - } - -let mapi = (~f, l) => mapi(0, f, l) - -let rev_map = (~f, l) => { - let rec rmap_f = (accu, param) => - switch param { - | list{} => accu - | list{a, ...l} => rmap_f(list{f(a), ...accu}, l) - } - - rmap_f(list{}, l) -} - -let rec iter = (~f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(a) - iter(~f, l) - } - -let rec iteri = (i, f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(i, a) - iteri(i + 1, f, l) - } - -let iteri = (~f, l) => iteri(0, f, l) - -let rec fold_left = (~f, ~init as accu, l) => - switch l { - | list{} => accu - | list{a, ...l} => fold_left(~f, ~init=f(accu, a), l) - } - -let rec fold_right = (~f, l, ~init as accu) => - switch l { - | list{} => accu - | list{a, ...l} => f(a, fold_right(~f, l, ~init=accu)) - } - -let rec map2 = (~f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => - let r = f(a1, a2) - list{r, ...map2(~f, l1, l2)} - | (_, _) => invalid_arg("List.map2") - } - -let rev_map2 = (~f, l1, l2) => { - let rec rmap2_f = (accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => rmap2_f(list{f(a1, a2), ...accu}, l1, l2) - | (_, _) => invalid_arg("List.rev_map2") - } - - rmap2_f(list{}, l1, l2) -} - -let rec iter2 = (~f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => () - | (list{a1, ...l1}, list{a2, ...l2}) => - f(a1, a2) - iter2(~f, l1, l2) - | (_, _) => invalid_arg("List.iter2") - } - -let rec fold_left2 = (~f, ~init as accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => fold_left2(~f, ~init=f(accu, a1, a2), l1, l2) - | (_, _) => invalid_arg("List.fold_left2") - } - -let rec fold_right2 = (~f, l1, l2, ~init as accu) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => f(a1, a2, fold_right2(~f, l1, l2, ~init=accu)) - | (_, _) => invalid_arg("List.fold_right2") - } - -let rec for_all = (~f as p, param) => - switch param { - | list{} => true - | list{a, ...l} => p(a) && for_all(~f=p, l) - } - -let rec exists = (~f as p, param) => - switch param { - | list{} => false - | list{a, ...l} => p(a) || exists(~f=p, l) - } - -let rec for_all2 = (~f as p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && for_all2(~f=p, l1, l2) - | (_, _) => invalid_arg("List.for_all2") - } - -let rec exists2 = (~f as p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => false - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || exists2(~f=p, l1, l2) - | (_, _) => invalid_arg("List.exists2") - } - -let rec mem = (x, ~set) => - switch set { - | list{} => false - | list{a, ...l} => compare(a, x) == 0 || mem(x, ~set=l) - } - -let rec memq = (x, ~set) => - switch set { - | list{} => false - | list{a, ...l} => a === x || memq(x, ~set=l) - } - -let rec assoc = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if compare(a, x) == 0 { - b - } else { - assoc(x, l) - } - } - -let rec assoc_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if compare(a, x) == 0 { - Some(b) - } else { - assoc_opt(x, l) - } - } - -let rec assq = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if a === x { - b - } else { - assq(x, l) - } - } - -let rec assq_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if a === x { - Some(b) - } else { - assq_opt(x, l) - } - } - -let rec mem_assoc = (x, ~map) => - switch map { - | list{} => false - | list{(a, _), ...l} => compare(a, x) == 0 || mem_assoc(x, ~map=l) - } - -let rec mem_assq = (x, ~map) => - switch map { - | list{} => false - | list{(a, _), ...l} => a === x || mem_assq(x, ~map=l) - } - -let rec remove_assoc = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if compare(a, x) == 0 { - l - } else { - list{pair, ...remove_assoc(x, l)} - } - } - -let rec remove_assq = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if a === x { - l - } else { - list{pair, ...remove_assq(x, l)} - } - } - -let rec find = (~f as p, param) => - switch param { - | list{} => raise(Not_found) - | list{x, ...l} => - if p(x) { - x - } else { - find(~f=p, l) - } - } - -let rec find_opt = (~f as p, param) => - switch param { - | list{} => None - | list{x, ...l} => - if p(x) { - Some(x) - } else { - find_opt(~f=p, l) - } - } - -let find_all = (~f as p, l) => { - let rec find = (accu, param) => - switch param { - | list{} => rev(accu) - | list{x, ...l} => - if p(x) { - find(list{x, ...accu}, l) - } else { - find(accu, l) - } - } - find(list{}, l) -} - -let filter = find_all - -let partition = (~f as p, l) => { - let rec part = (yes, no, param) => - switch param { - | list{} => (rev(yes), rev(no)) - | list{x, ...l} => - if p(x) { - part(list{x, ...yes}, no, l) - } else { - part(yes, list{x, ...no}, l) - } - } - part(list{}, list{}, l) -} - -let rec split = param => - switch param { - | list{} => (list{}, list{}) - | list{(x, y), ...l} => - let (rx, ry) = split(l) - (list{x, ...rx}, list{y, ...ry}) - } - -let rec combine = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => list{(a1, a2), ...combine(l1, l2)} - | (_, _) => invalid_arg("List.combine") - } - -/* sorting */ - -let rec merge = (~cmp, l1, l2) => - switch (l1, l2) { - | (list{}, l2) => l2 - | (l1, list{}) => l1 - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - list{h1, ...merge(~cmp, t1, l2)} - } else { - list{h2, ...merge(~cmp, l1, t2)} - } - } - -let rec chop = (k, l) => - if k == 0 { - l - } else { - switch l { - | list{_, ...t} => chop(k - 1, t) - | _ => assert(false) - } - } - -let stable_sort = (~cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) <= 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) <= 0 { - if cmp(x2, x3) <= 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) <= 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) <= 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) <= 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) > 0 { - if cmp(x2, x3) > 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) > 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let sort = stable_sort -let fast_sort = stable_sort - -/* Note: on a list of length between about 100000 (depending on the minor - heap size and the type of the list) and Sys.max_array_size, it is - actually faster to use the following, but it might also use more memory - because the argument list cannot be deallocated incrementally. - - Also, there seems to be a bug in this code or in the - implementation of obj_truncate. - -external obj_truncate : 'a array -> int -> unit = "caml_obj_truncate" - -let array_to_list_in_place a = - let l = Array.length a in - let rec loop accu n p = - if p <= 0 then accu else begin - if p = n then begin - obj_truncate a p; - loop (a.(p-1) :: accu) (n-1000) (p-1) - end else begin - loop (a.(p-1) :: accu) n (p-1) - end - end - in - loop [] (l-1000) l - - -let stable_sort cmp l = - let a = Array.of_list l in - Array.stable_sort cmp a; - array_to_list_in_place a -*/ - -/* sorting + removing duplicates */ - -let sort_uniq = (~cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge(t1, t2, list{h1, ...accu}) - } else if c < 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge_rev(t1, t2, list{h1, ...accu}) - } else if c > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c < 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c < 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c < 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c > 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c > 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let rec compare_lengths = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => 0 - | (list{}, _) => -1 - | (_, list{}) => 1 - | (list{_, ...l1}, list{_, ...l2}) => compare_lengths(l1, l2) - } - -let rec compare_length_with = (l, ~len as n) => - switch l { - | list{} => - if n == 0 { - 0 - } else if n > 0 { - -1 - } else { - 1 - } - | list{_, ...l} => - if n <= 0 { - 1 - } else { - compare_length_with(l, ~len=n - 1) - } - } diff --git a/jscomp/stdlib-406/listLabels.resi b/jscomp/stdlib-406/listLabels.resi deleted file mode 100644 index c48e830a47..0000000000 --- a/jscomp/stdlib-406/listLabels.resi +++ /dev/null @@ -1,337 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** List operations. - - Some functions are flagged as not tail-recursive. A tail-recursive - function uses constant stack space, while a non-tail-recursive function - uses stack space proportional to the length of its list argument, which - can be a problem with very long lists. When the function takes several - list arguments, an approximate formula giving stack usage (in some - unspecified constant unit) is shown in parentheses. - - The above considerations can usually be ignored if your lists are not - longer than about 10000 elements. -*/ - -/** Return the length (number of elements) of the given list. */ -let length: list<'a> => int - -/** Return the first element of the given list. Raise - [Failure "hd"] if the list is empty. */ -let hd: list<'a> => 'a - -/** Compare the lengths of two lists. [compare_lengths l1 l2] is - equivalent to [compare (length l1) (length l2)], except that - the computation stops after itering on the shortest list. - @since 4.05.0 - */ -let compare_lengths: (list<'a>, list<'b>) => int - -/** Compare the length of a list to an integer. [compare_length_with l n] is - equivalent to [compare (length l) n], except that - the computation stops after at most [n] iterations on the list. - @since 4.05.0 -*/ -let compare_length_with: (list<'a>, ~len: int) => int - -/** [cons x xs] is [x :: xs] - @since 4.05.0 -*/ -let cons: ('a, list<'a>) => list<'a> - -/** Return the given list without its first element. Raise - [Failure "tl"] if the list is empty. */ -let tl: list<'a> => list<'a> - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Raise [Failure "nth"] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. */ -let nth: (list<'a>, int) => 'a - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Return [None] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. - @since 4.05 -*/ -let nth_opt: (list<'a>, int) => option<'a> - -/** List reversal. */ -let rev: list<'a> => list<'a> - -/** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. - - @raise Invalid_argument if [len < 0]. - @since 4.06.0 -*/ -let init: (~len: int, ~f: int => 'a) => list<'a> - -/** Catenate two lists. Same function as the infix operator [@]. - Not tail-recursive (length of the first argument). The [@] - operator is not tail-recursive either. */ -let append: (list<'a>, list<'a>) => list<'a> - -/** [List.rev_append l1 l2] reverses [l1] and concatenates it with [l2]. - This is equivalent to [(]{!List.rev}[ l1) @ l2], but [rev_append] is - tail-recursive and more efficient. */ -let rev_append: (list<'a>, list<'a>) => list<'a> - -/** Concatenate a list of lists. The elements of the argument are all - concatenated together (in the same order) to give the result. - Not tail-recursive - (length of the argument + length of the longest sub-list). */ -let concat: list> => list<'a> - -/** Same as [concat]. Not tail-recursive - (length of the argument + length of the longest sub-list). */ -let flatten: list> => list<'a> - -/* {1 Iterators} */ - -/** [List.iter f [a1; ...; an]] applies function [f] in turn to - [a1; ...; an]. It is equivalent to - [begin f a1; f a2; ...; f an; () end]. */ -let iter: (~f: 'a => unit, list<'a>) => unit - -/** Same as {!List.iter}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -let iteri: (~f: (int, 'a) => unit, list<'a>) => unit - -/** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], - and builds the list [[f a1; ...; f an]] - with the results returned by [f]. Not tail-recursive. */ -let map: (~f: 'a => 'b, list<'a>) => list<'b> - -/** Same as {!List.map}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -let mapi: (~f: (int, 'a) => 'b, list<'a>) => list<'b> - -/** [List.rev_map f l] gives the same result as - {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and - more efficient. */ -let rev_map: (~f: 'a => 'b, list<'a>) => list<'b> - -/** [List.fold_left f a [b1; ...; bn]] is - [f (... (f (f a b1) b2) ...) bn]. */ -let fold_left: (~f: ('a, 'b) => 'a, ~init: 'a, list<'b>) => 'a - -/** [List.fold_right f [a1; ...; an] b] is - [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. */ -let fold_right: (~f: ('a, 'b) => 'b, list<'a>, ~init: 'b) => 'b - -/* {1 Iterators on two lists} */ - -/** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn - [f a1 b1; ...; f an bn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let iter2: (~f: ('a, 'b) => unit, list<'a>, list<'b>) => unit - -/** [List.map2 f [a1; ...; an] [b1; ...; bn]] is - [[f a1 b1; ...; f an bn]]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let map2: (~f: ('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.rev_map2 f l1 l2] gives the same result as - {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and - more efficient. */ -let rev_map2: (~f: ('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is - [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let fold_left2: (~f: ('a, 'b, 'c) => 'a, ~init: 'a, list<'b>, list<'c>) => 'a - -/** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is - [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let fold_right2: (~f: ('a, 'b, 'c) => 'c, list<'a>, list<'b>, ~init: 'c) => 'c - -/* {1 List scanning} */ - -/** [for_all p [a1; ...; an]] checks if all elements of the list - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. */ -let for_all: (~f: 'a => bool, list<'a>) => bool - -/** [exists p [a1; ...; an]] checks if at least one element of - the list satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. */ -let exists: (~f: 'a => bool, list<'a>) => bool - -/** Same as {!List.for_all}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let for_all2: (~f: ('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** Same as {!List.exists}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let exists2: (~f: ('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** [mem a l] is true if and only if [a] is equal - to an element of [l]. */ -let mem: ('a, ~set: list<'a>) => bool - -/** Same as {!List.mem}, but uses physical equality instead of structural - equality to compare list elements. */ -let memq: ('a, ~set: list<'a>) => bool - -/* {1 List searching} */ - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Raise [Not_found] if there is no value that satisfies [p] in the - list [l]. */ -let find: (~f: 'a => bool, list<'a>) => 'a - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Returns [None] if there is no value that satisfies [p] in the - list [l]. - @since 4.05 */ -let find_opt: (~f: 'a => bool, list<'a>) => option<'a> - -/** [filter p l] returns all the elements of the list [l] - that satisfy the predicate [p]. The order of the elements - in the input list is preserved. */ -let filter: (~f: 'a => bool, list<'a>) => list<'a> - -/** [find_all] is another name for {!List.filter}. */ -let find_all: (~f: 'a => bool, list<'a>) => list<'a> - -/** [partition p l] returns a pair of lists [(l1, l2)], where - [l1] is the list of all the elements of [l] that - satisfy the predicate [p], and [l2] is the list of all the - elements of [l] that do not satisfy [p]. - The order of the elements in the input list is preserved. */ -let partition: (~f: 'a => bool, list<'a>) => (list<'a>, list<'a>) - -/* {1 Association lists} */ - -/** [assoc a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Raise [Not_found] if there is no value associated with [a] in the - list [l]. */ -let assoc: ('a, list<('a, 'b)>) => 'b - -/** [assoc_opt a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Returns [None] if there is no value associated with [a] in the - list [l]. - @since 4.05 -*/ -let assoc_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but uses physical equality instead of - structural equality to compare keys. */ -let assq: ('a, list<('a, 'b)>) => 'b - -/** Same as {!List.assoc_opt}, but uses physical equality instead of - structural equality to compare keys. - @since 4.05.0 */ -let assq_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but simply return true if a binding exists, - and false if no bindings exist for the given key. */ -let mem_assoc: ('a, ~map: list<('a, 'b)>) => bool - -/** Same as {!List.mem_assoc}, but uses physical equality instead of - structural equality to compare keys. */ -let mem_assq: ('a, ~map: list<('a, 'b)>) => bool - -/** [remove_assoc a l] returns the list of - pairs [l] without the first pair with key [a], if any. - Not tail-recursive. */ -let remove_assoc: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/** Same as {!List.remove_assoc}, but uses physical equality instead - of structural equality to compare keys. Not tail-recursive. */ -let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/* {1 Lists of pairs} */ - -/** Transform a list of pairs into a pair of lists: - [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. - Not tail-recursive. -*/ -let split: list<('a, 'b)> => (list<'a>, list<'b>) - -/** Transform a pair of lists into a list of pairs: - [combine [a1; ...; an] [b1; ...; bn]] is - [[(a1,b1); ...; (an,bn)]]. - Raise [Invalid_argument] if the two lists - have different lengths. Not tail-recursive. */ -let combine: (list<'a>, list<'b>) => list<('a, 'b)> - -/* {1 Sorting} */ - -/** Sort a list in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see Array.sort for - a complete specification). For example, - {!Pervasives.compare} is a suitable comparison function. - The resulting list is sorted in increasing order. - [List.sort] is guaranteed to run in constant heap space - (in addition to the size of the result list) and logarithmic - stack space. - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but the sorting algorithm is guaranteed to - be stable (i.e. elements that compare equal are kept in their - original order) . - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let stable_sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort} or {!List.stable_sort}, whichever is - faster on typical input. */ -let fast_sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but also remove duplicates. - @since 4.03.0 */ -let sort_uniq: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Merge two lists: - Assuming that [l1] and [l2] are sorted according to the - comparison function [cmp], [merge cmp l1 l2] will return a - sorted list containing all the elements of [l1] and [l2]. - If several elements compare equal, the elements of [l1] will be - before the elements of [l2]. - Not tail-recursive (sum of the lengths of the arguments). -*/ -let merge: (~cmp: ('a, 'a) => int, list<'a>, list<'a>) => list<'a> diff --git a/jscomp/stdlib-406/map.res b/jscomp/stdlib-406/map.res deleted file mode 100644 index f485f302e2..0000000000 --- a/jscomp/stdlib-406/map.res +++ /dev/null @@ -1,669 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type key - type t<+'a> - let empty: t<'a> - let is_empty: t<'a> => bool - let mem: (key, t<'a>) => bool - let add: (key, 'a, t<'a>) => t<'a> - let update: (key, option<'a> => option<'a>, t<'a>) => t<'a> - let singleton: (key, 'a) => t<'a> - let remove: (key, t<'a>) => t<'a> - let merge: ((key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - let union: ((key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - let compare: (('a, 'a) => int, t<'a>, t<'a>) => int - let equal: (('a, 'a) => bool, t<'a>, t<'a>) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let for_all: ((key, 'a) => bool, t<'a>) => bool - let exists: ((key, 'a) => bool, t<'a>) => bool - let filter: ((key, 'a) => bool, t<'a>) => t<'a> - let partition: ((key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - let cardinal: t<'a> => int - let bindings: t<'a> => list<(key, 'a)> - let min_binding: t<'a> => (key, 'a) - let min_binding_opt: t<'a> => option<(key, 'a)> - let max_binding: t<'a> => (key, 'a) - let max_binding_opt: t<'a> => option<(key, 'a)> - let choose: t<'a> => (key, 'a) - let choose_opt: t<'a> => option<(key, 'a)> - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - let find: (key, t<'a>) => 'a - let find_opt: (key, t<'a>) => option<'a> - let find_first: (key => bool, t<'a>) => (key, 'a) - let find_first_opt: (key => bool, t<'a>) => option<(key, 'a)> - let find_last: (key => bool, t<'a>) => (key, 'a) - let find_last_opt: (key => bool, t<'a>) => option<(key, 'a)> - let map: ('a => 'b, t<'a>) => t<'b> - let mapi: ((key, 'a) => 'b, t<'a>) => t<'b> -} - -module Make = (Ord: OrderedType) => { - type key = Ord.t - - type rec t<'a> = - | Empty - | Node({l: t<'a>, v: key, d: 'a, r: t<'a>, h: int}) - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - let create = (l, x, d, r) => { - let hl = height(l) and hr = height(r) - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - let singleton = (x, d) => Node({l: Empty, v: x, d, r: Empty, h: 1}) - - let bal = (l, x, d, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Map.bal") - | Node({l: ll, v: lv, d: ld, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, ld, create(lr, x, d, r)) - } else { - switch lr { - | Empty => invalid_arg("Map.bal") - | Node({l: lrl, v: lrv, d: lrd, r: lrr}) => - create(create(ll, lv, ld, lrl), lrv, lrd, create(lrr, x, d, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Map.bal") - | Node({l: rl, v: rv, d: rd, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, x, d, rl), rv, rd, rr) - } else { - switch rl { - | Empty => invalid_arg("Map.bal") - | Node({l: rll, v: rlv, d: rld, r: rlr}) => - create(create(l, x, d, rll), rlv, rld, create(rlr, rv, rd, rr)) - } - } - } - } else { - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec add = (x, data, param) => - switch param { - | Empty => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } else if c < 0 { - let ll = add(x, data, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = add(x, data, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - d - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first_aux(v0, d0, f, r) - } - } - - let rec find_first = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first(f, r) - } - } - - let rec find_first_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt_aux(v0, d0, f, r) - } - } - - let rec find_first_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt(f, r) - } - } - - let rec find_last_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last_aux(v0, d0, f, l) - } - } - - let rec find_last = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last(f, l) - } - } - - let rec find_last_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt_aux(v0, d0, f, l) - } - } - - let rec find_last_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt(f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(d) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec min_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v, d}) => (v, d) - | Node({l}) => min_binding(l) - } - - let rec min_binding_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v, d}) => Some(v, d) - | Node({l}) => min_binding_opt(l) - } - - let rec max_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({v, d, r: Empty}) => (v, d) - | Node({r}) => max_binding(r) - } - - let rec max_binding_opt = param => - switch param { - | Empty => None - | Node({v, d, r: Empty}) => Some(v, d) - | Node({r}) => max_binding_opt(r) - } - - let rec remove_min_binding = param => - switch param { - | Empty => invalid_arg("Map.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, d, r}) => bal(remove_min_binding(l), v, d, r) - } - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - bal(t1, x, d, remove_min_binding(t2)) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = remove(x, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec update = (x, f, param) => - switch param { - | Empty => - switch f(None) { - | None => Empty - | Some(data) => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - } - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - switch f(Some(d)) { - | None => merge(l, r) - | Some(data) => - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } - } else if c < 0 { - let ll = update(x, f, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = update(x, f, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec iter = (f, param) => - switch param { - | Empty => () - | Node({l, v, d, r}) => - iter(f, l) - f(v, d) - iter(f, r) - } - - let rec map = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = map(f, l) - let d' = f(d) - let r' = map(f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec mapi = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = mapi(f, l) - let d' = f(v, d) - let r' = mapi(f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec fold = (f, m, accu) => - switch m { - | Empty => accu - | Node({l, v, d, r}) => fold(f, r, f(v, d, fold(f, l, accu))) - } - - let rec for_all = (p, param) => - switch param { - | Empty => true - | Node({l, v, d, r}) => p(v, d) && (for_all(p, l) && for_all(p, r)) - } - - let rec exists = (p, param) => - switch param { - | Empty => false - | Node({l, v, d, r}) => p(v, d) || (exists(p, l) || exists(p, r)) - } - - /* Beware: those two functions assume that the added k is *strictly* - smaller (or bigger) than all the present keys in the tree; it - does not test for equality with the current min (or max) key. - - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(add_min_binding(k, x, l), v, d, r) - } - - let rec add_max_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(l, v, d, add_max_binding(k, x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, d, r) => - switch (l, r) { - | (Empty, _) => add_min_binding(v, d, r) - | (_, Empty) => add_max_binding(v, d, l) - | (Node({l: ll, v: lv, d: ld, r: lr, h: lh}), Node({l: rl, v: rv, d: rd, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, ld, join(lr, v, d, r)) - } else if rh > lh + 2 { - bal(join(l, v, d, rl), rv, rd, rr) - } else { - create(l, v, d, r) - } - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - join(t1, x, d, remove_min_binding(t2)) - } - - let concat_or_join = (t1, v, d, t2) => - switch d { - | Some(d) => join(t1, v, d, t2) - | None => concat(t1, t2) - } - - let rec split = (x, param) => - switch param { - | Empty => (Empty, None, Empty) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, Some(d), r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, d, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, d, lr), pres, rr) - } - } - - let rec merge = (f, s1, s2) => - switch (s1, s2) { - | (Empty, Empty) => Empty - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), _) if h1 >= height(s2) => - let (l2, d2, r2) = split(v1, s2) - concat_or_join(merge(f, l1, l2), v1, f(v1, Some(d1), d2), merge(f, r1, r2)) - | (_, Node({l: l2, v: v2, d: d2, r: r2})) => - let (l1, d1, r1) = split(v2, s1) - concat_or_join(merge(f, l1, l2), v2, f(v2, d1, Some(d2)), merge(f, r1, r2)) - | _ => assert(false) - } - - let rec union = (f, s1, s2) => - switch (s1, s2) { - | (Empty, s) | (s, Empty) => s - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), Node({l: l2, v: v2, d: d2, r: r2, h: h2})) => - if h1 >= h2 { - let (l2, d2, r2) = split(v1, s2) - let l = union(f, l1, l2) and r = union(f, r1, r2) - switch d2 { - | None => join(l, v1, d1, r) - | Some(d2) => concat_or_join(l, v1, f(v1, d1, d2), r) - } - } else { - let (l1, d1, r1) = split(v2, s1) - let l = union(f, l1, l2) and r = union(f, r1, r2) - switch d1 { - | None => join(l, v2, d2, r) - | Some(d1) => concat_or_join(l, v2, f(v2, d1, d2), r) - } - } - } - - let rec filter = (p, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - /* call [p] in the expected left-to-right order */ - let l' = filter(p, l) - let pvd = p(v, d) - let r' = filter(p, r) - if pvd { - if l === l' && r === r' { - m - } else { - join(l', v, d, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, d, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(p, l) - let pvd = p(v, d) - let (rt, rf) = partition(p, r) - if pvd { - (join(lt, v, d, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, d, rf)) - } - } - - type rec enumeration<'a> = End | More(key, 'a, t<'a>, enumeration<'a>) - - let rec cons_enum = (m, e) => - switch m { - | Empty => e - | Node({l, v, d, r}) => cons_enum(l, More(v, d, r, e)) - } - - let compare = (cmp, m1, m2) => { - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - let c = cmp(d1, d2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - } - compare_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let equal = (cmp, m1, m2) => { - let rec equal_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => true - | (End, _) => false - | (_, End) => false - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - Ord.compare(v1, v2) == 0 && (cmp(d1, d2) && equal_aux(cons_enum(r1, e1), cons_enum(r2, e2))) - } - equal_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec bindings_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, d, r}) => bindings_aux(list{(v, d), ...bindings_aux(accu, r)}, l) - } - - let bindings = s => bindings_aux(list{}, s) - - let choose = min_binding - - let choose_opt = min_binding_opt -} diff --git a/jscomp/stdlib-406/map.resi b/jscomp/stdlib-406/map.resi deleted file mode 100644 index 11458cb69a..0000000000 --- a/jscomp/stdlib-406/map.resi +++ /dev/null @@ -1,310 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** Association tables over ordered types. - - This module implements applicative association tables, also known as - finite maps or dictionaries, given a total ordering function - over the keys. - All operations over maps are purely applicative (no side-effects). - The implementation uses balanced binary trees, and therefore searching - and insertion take time logarithmic in the size of the map. - - For instance: - {[ - module IntPairs = - struct - type t = int * int - let compare (x0,y0) (x1,y1) = - match Pervasives.compare x0 x1 with - 0 -> Pervasives.compare y0 y1 - | c -> c - end - - module PairsMap = Map.Make(IntPairs) - - let m = PairsMap.(empty |> add (0,1) \"hello\" |> add (1,0) \"world\") - ]} - - This creates a new module [PairsMap], with a new type ['a PairsMap.t] - of maps from [int * int] to ['a]. In this example, [m] contains [string] - values so its type is [string PairsMap.t]. -*/ - -/** Input signature of the functor {!Map.Make}. */ -module type OrderedType = { - /** The type of the map keys. */ - type t - - /** A total ordering function over the keys. - This is a two-argument function [f] such that - [f e1 e2] is zero if the keys [e1] and [e2] are equal, - [f e1 e2] is strictly negative if [e1] is smaller than [e2], - and [f e1 e2] is strictly positive if [e1] is greater than [e2]. - Example: a suitable ordering function is the generic structural - comparison function {!Pervasives.compare}. */ - let compare: (t, t) => int -} - -/** Output signature of the functor {!Map.Make}. */ -module type S = { - /** The type of the map keys. */ - type key - - /** The type of maps from type [key] to type ['a]. */ - type t<+'a> - - /** The empty map. */ - let empty: t<'a> - - /** Test whether a map is empty or not. */ - let is_empty: t<'a> => bool - - /** [mem x m] returns [true] if [m] contains a binding for [x], - and [false] otherwise. */ - let mem: (key, t<'a>) => bool - - /** [add x y m] returns a map containing the same bindings as - [m], plus a binding of [x] to [y]. If [x] was already bound - in [m] to a value that is physically equal to [y], - [m] is returned unchanged (the result of the function is - then physically equal to [m]). Otherwise, the previous binding - of [x] in [m] disappears. - @before 4.03 Physical equality was not ensured. */ - let add: (key, 'a, t<'a>) => t<'a> - - /** [update x f m] returns a map containing the same bindings as - [m], except for the binding of [x]. Depending on the value of - [y] where [y] is [f (find_opt x m)], the binding of [x] is - added, removed or updated. If [y] is [None], the binding is - removed if it exists; otherwise, if [y] is [Some z] then [x] - is associated to [z] in the resulting map. If [x] was already - bound in [m] to a value that is physically equal to [z], [m] - is returned unchanged (the result of the function is then - physically equal to [m]). - @since 4.06.0 - */ - let update: (key, option<'a> => option<'a>, t<'a>) => t<'a> - - /** [singleton x y] returns the one-element map that contains a binding [y] - for [x]. - @since 3.12.0 - */ - let singleton: (key, 'a) => t<'a> - - /** [remove x m] returns a map containing the same bindings as - [m], except for [x] which is unbound in the returned map. - If [x] was not in [m], [m] is returned unchanged - (the result of the function is then physically equal to [m]). - @before 4.03 Physical equality was not ensured. */ - let remove: (key, t<'a>) => t<'a> - - /** [merge f m1 m2] computes a map whose keys is a subset of keys of [m1] - and of [m2]. The presence of each such binding, and the corresponding - value, is determined with the function [f]. - In terms of the [find_opt] operation, we have - [find_opt x (merge f m1 m2) = f (find_opt x m1) (find_opt x m2)] - for any key [x], provided that [f None None = None]. - @since 3.12.0 - */ - let merge: ((key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - - /** [union f m1 m2] computes a map whose keys is the union of keys - of [m1] and of [m2]. When the same binding is defined in both - arguments, the function [f] is used to combine them. - This is a special case of [merge]: [union f m1 m2] is equivalent - to [merge f' m1 m2], where - - [f' None None = None] - - [f' (Some v) None = Some v] - - [f' None (Some v) = Some v] - - [f' (Some v1) (Some v2) = f v1 v2] - - @since 4.03.0 - */ - let union: ((key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - - /** Total ordering between maps. The first argument is a total ordering - used to compare data associated with equal keys in the two maps. */ - let compare: (('a, 'a) => int, t<'a>, t<'a>) => int - - /** [equal cmp m1 m2] tests whether the maps [m1] and [m2] are - equal, that is, contain equal keys and associate them with - equal data. [cmp] is the equality predicate used to compare - the data associated with the keys. */ - let equal: (('a, 'a) => bool, t<'a>, t<'a>) => bool - - /** [iter f m] applies [f] to all bindings in map [m]. - [f] receives the key as first argument, and the associated value - as second argument. The bindings are passed to [f] in increasing - order with respect to the ordering over the type of the keys. */ - let iter: ((key, 'a) => unit, t<'a>) => unit - - /** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)], - where [k1 ... kN] are the keys of all bindings in [m] - (in increasing order), and [d1 ... dN] are the associated data. */ - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - - /** [for_all p m] checks if all the bindings of the map - satisfy the predicate [p]. - @since 3.12.0 - */ - let for_all: ((key, 'a) => bool, t<'a>) => bool - - /** [exists p m] checks if at least one binding of the map - satisfies the predicate [p]. - @since 3.12.0 - */ - let exists: ((key, 'a) => bool, t<'a>) => bool - - /** [filter p m] returns the map with all the bindings in [m] - that satisfy predicate [p]. If [p] satisfies every binding in [m], - [m] is returned unchanged (the result of the function is then - physically equal to [m]) - @since 3.12.0 - @before 4.03 Physical equality was not ensured. - */ - let filter: ((key, 'a) => bool, t<'a>) => t<'a> - - /** [partition p m] returns a pair of maps [(m1, m2)], where - [m1] contains all the bindings of [s] that satisfy the - predicate [p], and [m2] is the map with all the bindings of - [s] that do not satisfy [p]. - @since 3.12.0 - */ - let partition: ((key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - - /** Return the number of bindings of a map. - @since 3.12.0 - */ - let cardinal: t<'a> => int - - /** Return the list of all bindings of the given map. - The returned list is sorted in increasing order with respect - to the ordering [Ord.compare], where [Ord] is the argument - given to {!Map.Make}. - @since 3.12.0 - */ - let bindings: t<'a> => list<(key, 'a)> - - /** Return the smallest binding of the given map - (with respect to the [Ord.compare] ordering), or raise - [Not_found] if the map is empty. - @since 3.12.0 - */ - let min_binding: t<'a> => (key, 'a) - - /** Return the smallest binding of the given map - (with respect to the [Ord.compare] ordering), or [None] - if the map is empty. - @since 4.05 - */ - let min_binding_opt: t<'a> => option<(key, 'a)> - - /** Same as {!Map.S.min_binding}, but returns the largest binding - of the given map. - @since 3.12.0 - */ - let max_binding: t<'a> => (key, 'a) - - /** Same as {!Map.S.min_binding_opt}, but returns the largest binding - of the given map. - @since 4.05 - */ - let max_binding_opt: t<'a> => option<(key, 'a)> - - /** Return one binding of the given map, or raise [Not_found] if - the map is empty. Which binding is chosen is unspecified, - but equal bindings will be chosen for equal maps. - @since 3.12.0 - */ - let choose: t<'a> => (key, 'a) - - /** Return one binding of the given map, or [None] if - the map is empty. Which binding is chosen is unspecified, - but equal bindings will be chosen for equal maps. - @since 4.05 - */ - let choose_opt: t<'a> => option<(key, 'a)> - - /** [split x m] returns a triple [(l, data, r)], where - [l] is the map with all the bindings of [m] whose key - is strictly less than [x]; - [r] is the map with all the bindings of [m] whose key - is strictly greater than [x]; - [data] is [None] if [m] contains no binding for [x], - or [Some v] if [m] binds [v] to [x]. - @since 3.12.0 - */ - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - - /** [find x m] returns the current binding of [x] in [m], - or raises [Not_found] if no such binding exists. */ - let find: (key, t<'a>) => 'a - - /** [find_opt x m] returns [Some v] if the current binding of [x] - in [m] is [v], or [None] if no such binding exists. - @since 4.05 - */ - let find_opt: (key, t<'a>) => option<'a> - - /** [find_first f m], where [f] is a monotonically increasing function, - returns the binding of [m] with the lowest key [k] such that [f k], - or raises [Not_found] if no such key exists. - - For example, [find_first (fun k -> Ord.compare k x >= 0) m] will return - the first binding [k, v] of [m] where [Ord.compare k x >= 0] - (intuitively: [k >= x]), or raise [Not_found] if [x] is greater than any - element of [m]. - - @since 4.05 - */ - let find_first: (key => bool, t<'a>) => (key, 'a) - - /** [find_first_opt f m], where [f] is a monotonically increasing function, - returns an option containing the binding of [m] with the lowest key [k] - such that [f k], or [None] if no such key exists. - @since 4.05 - */ - let find_first_opt: (key => bool, t<'a>) => option<(key, 'a)> - - /** [find_last f m], where [f] is a monotonically decreasing function, - returns the binding of [m] with the highest key [k] such that [f k], - or raises [Not_found] if no such key exists. - @since 4.05 - */ - let find_last: (key => bool, t<'a>) => (key, 'a) - - /** [find_last_opt f m], where [f] is a monotonically decreasing function, - returns an option containing the binding of [m] with the highest key [k] - such that [f k], or [None] if no such key exists. - @since 4.05 - */ - let find_last_opt: (key => bool, t<'a>) => option<(key, 'a)> - - /** [map f m] returns a map with same domain as [m], where the - associated value [a] of all bindings of [m] has been - replaced by the result of the application of [f] to [a]. - The bindings are passed to [f] in increasing order - with respect to the ordering over the type of the keys. */ - let map: ('a => 'b, t<'a>) => t<'b> - - /** Same as {!Map.S.map}, but the function receives as arguments both the - key and the associated value for each binding of the map. */ - let mapi: ((key, 'a) => 'b, t<'a>) => t<'b> -} - -/** Functor building an implementation of the map structure - given a totally ordered type. */ -module Make: (Ord: OrderedType) => (S with type key = Ord.t) diff --git a/jscomp/stdlib-406/mapLabels.res b/jscomp/stdlib-406/mapLabels.res deleted file mode 100644 index 7a1a395075..0000000000 --- a/jscomp/stdlib-406/mapLabels.res +++ /dev/null @@ -1,669 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type key - type t<+'a> - let empty: t<'a> - let is_empty: t<'a> => bool - let mem: (key, t<'a>) => bool - let add: (~key: key, ~data: 'a, t<'a>) => t<'a> - let update: (~key: key, ~f: option<'a> => option<'a>, t<'a>) => t<'a> - let singleton: (key, 'a) => t<'a> - let remove: (key, t<'a>) => t<'a> - let merge: (~f: (key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - let union: (~f: (key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - let compare: (~cmp: ('a, 'a) => int, t<'a>, t<'a>) => int - let equal: (~cmp: ('a, 'a) => bool, t<'a>, t<'a>) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let for_all: (~f: (key, 'a) => bool, t<'a>) => bool - let exists: (~f: (key, 'a) => bool, t<'a>) => bool - let filter: (~f: (key, 'a) => bool, t<'a>) => t<'a> - let partition: (~f: (key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - let cardinal: t<'a> => int - let bindings: t<'a> => list<(key, 'a)> - let min_binding: t<'a> => (key, 'a) - let min_binding_opt: t<'a> => option<(key, 'a)> - let max_binding: t<'a> => (key, 'a) - let max_binding_opt: t<'a> => option<(key, 'a)> - let choose: t<'a> => (key, 'a) - let choose_opt: t<'a> => option<(key, 'a)> - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - let find: (key, t<'a>) => 'a - let find_opt: (key, t<'a>) => option<'a> - let find_first: (~f: key => bool, t<'a>) => (key, 'a) - let find_first_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let find_last: (~f: key => bool, t<'a>) => (key, 'a) - let find_last_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let map: (~f: 'a => 'b, t<'a>) => t<'b> - let mapi: (~f: (key, 'a) => 'b, t<'a>) => t<'b> -} - -module Make = (Ord: OrderedType) => { - type key = Ord.t - - type rec t<'a> = - | Empty - | Node({l: t<'a>, v: key, d: 'a, r: t<'a>, h: int}) - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - let create = (l, x, d, r) => { - let hl = height(l) and hr = height(r) - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - let singleton = (x, d) => Node({l: Empty, v: x, d, r: Empty, h: 1}) - - let bal = (l, x, d, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Map.bal") - | Node({l: ll, v: lv, d: ld, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, ld, create(lr, x, d, r)) - } else { - switch lr { - | Empty => invalid_arg("Map.bal") - | Node({l: lrl, v: lrv, d: lrd, r: lrr}) => - create(create(ll, lv, ld, lrl), lrv, lrd, create(lrr, x, d, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Map.bal") - | Node({l: rl, v: rv, d: rd, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, x, d, rl), rv, rd, rr) - } else { - switch rl { - | Empty => invalid_arg("Map.bal") - | Node({l: rll, v: rlv, d: rld, r: rlr}) => - create(create(l, x, d, rll), rlv, rld, create(rlr, rv, rd, rr)) - } - } - } - } else { - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec add = (~key as x, ~data, param) => - switch param { - | Empty => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } else if c < 0 { - let ll = add(~key=x, ~data, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = add(~key=x, ~data, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - d - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first_aux(v0, d0, f, r) - } - } - - let rec find_first = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first(~f, r) - } - } - - let rec find_first_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt_aux(v0, d0, f, r) - } - } - - let rec find_first_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt(~f, r) - } - } - - let rec find_last_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last_aux(v0, d0, f, l) - } - } - - let rec find_last = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last(~f, l) - } - } - - let rec find_last_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt_aux(v0, d0, f, l) - } - } - - let rec find_last_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt(~f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(d) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec min_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v, d}) => (v, d) - | Node({l}) => min_binding(l) - } - - let rec min_binding_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v, d}) => Some(v, d) - | Node({l}) => min_binding_opt(l) - } - - let rec max_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({v, d, r: Empty}) => (v, d) - | Node({r}) => max_binding(r) - } - - let rec max_binding_opt = param => - switch param { - | Empty => None - | Node({v, d, r: Empty}) => Some(v, d) - | Node({r}) => max_binding_opt(r) - } - - let rec remove_min_binding = param => - switch param { - | Empty => invalid_arg("Map.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, d, r}) => bal(remove_min_binding(l), v, d, r) - } - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - bal(t1, x, d, remove_min_binding(t2)) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = remove(x, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec update = (~key as x, ~f, param) => - switch param { - | Empty => - switch f(None) { - | None => Empty - | Some(data) => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - } - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - switch f(Some(d)) { - | None => merge(l, r) - | Some(data) => - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } - } else if c < 0 { - let ll = update(~key=x, ~f, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = update(~key=x, ~f, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec iter = (~f, param) => - switch param { - | Empty => () - | Node({l, v, d, r}) => - iter(~f, l) - f(~key=v, ~data=d) - iter(~f, r) - } - - let rec map = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = map(~f, l) - let d' = f(d) - let r' = map(~f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec mapi = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = mapi(~f, l) - let d' = f(v, d) - let r' = mapi(~f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec fold = (~f, m, ~init as accu) => - switch m { - | Empty => accu - | Node({l, v, d, r}) => fold(~f, r, ~init=f(~key=v, ~data=d, fold(~f, l, ~init=accu))) - } - - let rec for_all = (~f as p, param) => - switch param { - | Empty => true - | Node({l, v, d, r}) => p(v, d) && (for_all(~f=p, l) && for_all(~f=p, r)) - } - - let rec exists = (~f as p, param) => - switch param { - | Empty => false - | Node({l, v, d, r}) => p(v, d) || (exists(~f=p, l) || exists(~f=p, r)) - } - - /* Beware: those two functions assume that the added k is *strictly* - smaller (or bigger) than all the present keys in the tree; it - does not test for equality with the current min (or max) key. - - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(add_min_binding(k, x, l), v, d, r) - } - - let rec add_max_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(l, v, d, add_max_binding(k, x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, d, r) => - switch (l, r) { - | (Empty, _) => add_min_binding(v, d, r) - | (_, Empty) => add_max_binding(v, d, l) - | (Node({l: ll, v: lv, d: ld, r: lr, h: lh}), Node({l: rl, v: rv, d: rd, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, ld, join(lr, v, d, r)) - } else if rh > lh + 2 { - bal(join(l, v, d, rl), rv, rd, rr) - } else { - create(l, v, d, r) - } - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - join(t1, x, d, remove_min_binding(t2)) - } - - let concat_or_join = (t1, v, d, t2) => - switch d { - | Some(d) => join(t1, v, d, t2) - | None => concat(t1, t2) - } - - let rec split = (x, param) => - switch param { - | Empty => (Empty, None, Empty) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, Some(d), r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, d, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, d, lr), pres, rr) - } - } - - let rec merge = (~f, s1, s2) => - switch (s1, s2) { - | (Empty, Empty) => Empty - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), _) if h1 >= height(s2) => - let (l2, d2, r2) = split(v1, s2) - concat_or_join(merge(~f, l1, l2), v1, f(v1, Some(d1), d2), merge(~f, r1, r2)) - | (_, Node({l: l2, v: v2, d: d2, r: r2})) => - let (l1, d1, r1) = split(v2, s1) - concat_or_join(merge(~f, l1, l2), v2, f(v2, d1, Some(d2)), merge(~f, r1, r2)) - | _ => assert(false) - } - - let rec union = (~f, s1, s2) => - switch (s1, s2) { - | (Empty, s) | (s, Empty) => s - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), Node({l: l2, v: v2, d: d2, r: r2, h: h2})) => - if h1 >= h2 { - let (l2, d2, r2) = split(v1, s2) - let l = union(~f, l1, l2) and r = union(~f, r1, r2) - switch d2 { - | None => join(l, v1, d1, r) - | Some(d2) => concat_or_join(l, v1, f(v1, d1, d2), r) - } - } else { - let (l1, d1, r1) = split(v2, s1) - let l = union(~f, l1, l2) and r = union(~f, r1, r2) - switch d1 { - | None => join(l, v2, d2, r) - | Some(d1) => concat_or_join(l, v2, f(v2, d1, d2), r) - } - } - } - - let rec filter = (~f as p, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - /* call [p] in the expected left-to-right order */ - let l' = filter(~f=p, l) - let pvd = p(v, d) - let r' = filter(~f=p, r) - if pvd { - if l === l' && r === r' { - m - } else { - join(l', v, d, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (~f as p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, d, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(~f=p, l) - let pvd = p(v, d) - let (rt, rf) = partition(~f=p, r) - if pvd { - (join(lt, v, d, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, d, rf)) - } - } - - type rec enumeration<'a> = End | More(key, 'a, t<'a>, enumeration<'a>) - - let rec cons_enum = (m, e) => - switch m { - | Empty => e - | Node({l, v, d, r}) => cons_enum(l, More(v, d, r, e)) - } - - let compare = (~cmp, m1, m2) => { - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - let c = cmp(d1, d2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - } - compare_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let equal = (~cmp, m1, m2) => { - let rec equal_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => true - | (End, _) => false - | (_, End) => false - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - Ord.compare(v1, v2) == 0 && (cmp(d1, d2) && equal_aux(cons_enum(r1, e1), cons_enum(r2, e2))) - } - equal_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec bindings_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, d, r}) => bindings_aux(list{(v, d), ...bindings_aux(accu, r)}, l) - } - - let bindings = s => bindings_aux(list{}, s) - - let choose = min_binding - - let choose_opt = min_binding_opt -} diff --git a/jscomp/stdlib-406/queue.res b/jscomp/stdlib-406/queue.res deleted file mode 100644 index 89d9297229..0000000000 --- a/jscomp/stdlib-406/queue.res +++ /dev/null @@ -1,142 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Francois Pottier, projet Cristal, INRIA Rocquencourt */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2002 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -exception Empty - -type rec cell<'a> = - | Nil - | Cons({content: 'a, mutable next: cell<'a>}) - -type t<'a> = { - mutable length: int, - mutable first: cell<'a>, - mutable last: cell<'a>, -} - -let create = () => { - length: 0, - first: Nil, - last: Nil, -} - -let clear = q => { - q.length = 0 - q.first = Nil - q.last = Nil -} - -let add = (x, q) => { - let cell = Cons({ - content: x, - next: Nil, - }) - switch q.last { - | Nil => - q.length = 1 - q.first = cell - q.last = cell - | Cons(last) => - q.length = q.length + 1 - last.next = cell - q.last = cell - } -} - -let push = add - -let peek = q => - switch q.first { - | Nil => raise(Empty) - | Cons({content}) => content - } - -let top = peek - -let take = q => - switch q.first { - | Nil => raise(Empty) - | Cons({content, next: Nil}) => - clear(q) - content - | Cons({content, next}) => - q.length = q.length - 1 - q.first = next - content - } - -let pop = take - -let copy = { - let rec copy = (q_res, prev, cell) => - switch cell { - | Nil => - q_res.last = prev - q_res - | Cons({content, next}) => - let res = Cons({content, next: Nil}) - switch prev { - | Nil => q_res.first = res - | Cons(p) => p.next = res - } - copy(q_res, res, next) - } - - q => copy({length: q.length, first: Nil, last: Nil}, Nil, q.first) -} - -let is_empty = q => q.length == 0 - -let length = q => q.length - -let iter = { - let rec iter = (f, cell) => - switch cell { - | Nil => () - | Cons({content, next}) => - f(content) - iter(f, next) - } - - (f, q) => iter(f, q.first) -} - -let fold = { - let rec fold = (f, accu, cell) => - switch cell { - | Nil => accu - | Cons({content, next}) => - let accu = f(accu, content) - fold(f, accu, next) - } - - (f, accu, q) => fold(f, accu, q.first) -} - -let transfer = (q1, q2) => - if q1.length > 0 { - switch q2.last { - | Nil => - q2.length = q1.length - q2.first = q1.first - q2.last = q1.last - clear(q1) - | Cons(last) => - q2.length = q2.length + q1.length - last.next = q1.first - q2.last = q1.last - clear(q1) - } - } diff --git a/jscomp/stdlib-406/queue.resi b/jscomp/stdlib-406/queue.resi deleted file mode 100644 index c5ed5ae64b..0000000000 --- a/jscomp/stdlib-406/queue.resi +++ /dev/null @@ -1,79 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** First-in first-out queues. - - This module implements queues (FIFOs), with in-place modification. - - {b Warning} This module is not thread-safe: each {!Queue.t} value - must be protected from concurrent access (e.g. with a [Mutex.t]). - Failure to do so can lead to a crash. -*/ - -/** The type of queues containing elements of type ['a]. */ -type t<'a> - -/** Raised when {!Queue.take} or {!Queue.peek} is applied to an empty queue. */ exception Empty - -/** Return a new queue, initially empty. */ -let create: unit => t<'a> - -/** [add x q] adds the element [x] at the end of the queue [q]. */ -let add: ('a, t<'a>) => unit - -/** [push] is a synonym for [add]. */ -let push: ('a, t<'a>) => unit - -/** [take q] removes and returns the first element in queue [q], - or raises {!Empty} if the queue is empty. */ -let take: t<'a> => 'a - -/** [pop] is a synonym for [take]. */ -let pop: t<'a> => 'a - -/** [peek q] returns the first element in queue [q], without removing - it from the queue, or raises {!Empty} if the queue is empty. */ -let peek: t<'a> => 'a - -/** [top] is a synonym for [peek]. */ -let top: t<'a> => 'a - -/** Discard all elements from a queue. */ -let clear: t<'a> => unit - -/** Return a copy of the given queue. */ -let copy: t<'a> => t<'a> - -/** Return [true] if the given queue is empty, [false] otherwise. */ -let is_empty: t<'a> => bool - -/** Return the number of elements in a queue. */ -let length: t<'a> => int - -/** [iter f q] applies [f] in turn to all elements of [q], - from the least recently entered to the most recently entered. - The queue itself is unchanged. */ -let iter: ('a => unit, t<'a>) => unit - -/** [fold f accu q] is equivalent to [List.fold_left f accu l], - where [l] is the list of [q]'s elements. The queue remains - unchanged. */ -let fold: (('b, 'a) => 'b, 'b, t<'a>) => 'b - -/** [transfer q1 q2] adds all of [q1]'s elements at the end of - the queue [q2], then clears [q1]. It is equivalent to the - sequence [iter (fun x -> add x q2) q1; clear q1], but runs - in constant time. */ -let transfer: (t<'a>, t<'a>) => unit diff --git a/jscomp/stdlib-406/release.ninja b/jscomp/stdlib-406/release.ninja index ea73a61756..36ea3dca69 100644 --- a/jscomp/stdlib-406/release.ninja +++ b/jscomp/stdlib-406/release.ninja @@ -20,28 +20,12 @@ o stdlib-406/camlinternalMod.cmj : cc_cmi stdlib-406/camlinternalMod.res | stdli o stdlib-406/camlinternalMod.cmi : cc stdlib-406/camlinternalMod.resi | stdlib-406/obj.cmi stdlib-406/pervasives.cmj $bsc others o stdlib-406/char.cmj : cc_cmi stdlib-406/char.res | stdlib-406/char.cmi $bsc others o stdlib-406/char.cmi : cc stdlib-406/char.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/complex.cmj : cc_cmi stdlib-406/complex.res | stdlib-406/complex.cmi $bsc others -o stdlib-406/complex.cmi : cc stdlib-406/complex.resi | stdlib-406/pervasives.cmj $bsc others o stdlib-406/hashtbl.cmj : cc_cmi stdlib-406/hashtbl.res | stdlib-406/hashtbl.cmi $bsc others o stdlib-406/hashtbl.cmi : cc stdlib-406/hashtbl.resi | stdlib-406/pervasives.cmj $bsc others o stdlib-406/lazy.cmj : cc_cmi stdlib-406/lazy.res | stdlib-406/camlinternalLazy.cmj stdlib-406/lazy.cmi $bsc others o stdlib-406/lazy.cmi : cc stdlib-406/lazy.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/list.cmj : cc_cmi stdlib-406/list.res | stdlib-406/list.cmi $bsc others -o stdlib-406/list.cmi : cc stdlib-406/list.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/listLabels.cmj : cc_cmi stdlib-406/listLabels.res | stdlib-406/listLabels.cmi $bsc others -o stdlib-406/listLabels.cmi : cc stdlib-406/listLabels.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/map.cmj : cc_cmi stdlib-406/map.res | stdlib-406/map.cmi $bsc others -o stdlib-406/map.cmi : cc stdlib-406/map.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/mapLabels.cmi stdlib-406/mapLabels.cmj : cc stdlib-406/mapLabels.res | stdlib-406/pervasives.cmj $bsc others o stdlib-406/obj.cmj : cc_cmi stdlib-406/obj.res | stdlib-406/obj.cmi $bsc others o stdlib-406/obj.cmi : cc stdlib-406/obj.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/queue.cmj : cc_cmi stdlib-406/queue.res | stdlib-406/queue.cmi $bsc others -o stdlib-406/queue.cmi : cc stdlib-406/queue.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/set.cmj : cc_cmi stdlib-406/set.res | stdlib-406/list.cmj stdlib-406/set.cmi $bsc others -o stdlib-406/set.cmi : cc stdlib-406/set.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/setLabels.cmi stdlib-406/setLabels.cmj : cc stdlib-406/setLabels.res | stdlib-406/list.cmj stdlib-406/pervasives.cmj $bsc others -o stdlib-406/stack.cmj : cc_cmi stdlib-406/stack.res | stdlib-406/list.cmj stdlib-406/stack.cmi $bsc others -o stdlib-406/stack.cmi : cc stdlib-406/stack.resi | stdlib-406/pervasives.cmj $bsc others o stdlib-406/string.cmj : cc_cmi stdlib-406/string.res | stdlib-406/string.cmi $bsc others o stdlib-406/string.cmi : cc stdlib-406/string.resi | stdlib-406/pervasives.cmj $bsc others -o $stdlib : phony stdlib-406/callback.cmi stdlib-406/callback.cmj stdlib-406/camlinternalLazy.cmi stdlib-406/camlinternalLazy.cmj stdlib-406/camlinternalMod.cmi stdlib-406/camlinternalMod.cmj stdlib-406/char.cmi stdlib-406/char.cmj stdlib-406/complex.cmi stdlib-406/complex.cmj stdlib-406/hashtbl.cmi stdlib-406/hashtbl.cmj stdlib-406/lazy.cmi stdlib-406/lazy.cmj stdlib-406/list.cmi stdlib-406/list.cmj stdlib-406/listLabels.cmi stdlib-406/listLabels.cmj stdlib-406/map.cmi stdlib-406/map.cmj stdlib-406/mapLabels.cmi stdlib-406/mapLabels.cmj stdlib-406/obj.cmi stdlib-406/obj.cmj stdlib-406/queue.cmi stdlib-406/queue.cmj stdlib-406/set.cmi stdlib-406/set.cmj stdlib-406/setLabels.cmi stdlib-406/setLabels.cmj stdlib-406/stack.cmi stdlib-406/stack.cmj stdlib-406/string.cmi stdlib-406/string.cmj +o $stdlib : phony stdlib-406/callback.cmi stdlib-406/callback.cmj stdlib-406/camlinternalLazy.cmi stdlib-406/camlinternalLazy.cmj stdlib-406/camlinternalMod.cmi stdlib-406/camlinternalMod.cmj stdlib-406/char.cmi stdlib-406/char.cmj stdlib-406/hashtbl.cmi stdlib-406/hashtbl.cmj stdlib-406/lazy.cmi stdlib-406/lazy.cmj stdlib-406/obj.cmi stdlib-406/obj.cmj stdlib-406/string.cmi stdlib-406/string.cmj diff --git a/jscomp/stdlib-406/set.res b/jscomp/stdlib-406/set.res deleted file mode 100644 index 49d30edd63..0000000000 --- a/jscomp/stdlib-406/set.res +++ /dev/null @@ -1,711 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/* Sets over ordered types */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type elt - type t - let empty: t - let is_empty: t => bool - let mem: (elt, t) => bool - let add: (elt, t) => t - let singleton: elt => t - let remove: (elt, t) => t - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let compare: (t, t) => int - let equal: (t, t) => bool - let subset: (t, t) => bool - let iter: (elt => unit, t) => unit - let map: (elt => elt, t) => t - let fold: ((elt, 'a) => 'a, t, 'a) => 'a - let for_all: (elt => bool, t) => bool - let exists: (elt => bool, t) => bool - let filter: (elt => bool, t) => t - let partition: (elt => bool, t) => (t, t) - let cardinal: t => int - let elements: t => list - let min_elt: t => elt - let min_elt_opt: t => option - let max_elt: t => elt - let max_elt_opt: t => option - let choose: t => elt - let choose_opt: t => option - let split: (elt, t) => (t, bool, t) - let find: (elt, t) => elt - let find_opt: (elt, t) => option - let find_first: (elt => bool, t) => elt - let find_first_opt: (elt => bool, t) => option - let find_last: (elt => bool, t) => elt - let find_last_opt: (elt => bool, t) => option - let of_list: list => t -} - -module Make = (Ord: OrderedType) => { - type elt = Ord.t - type rec t = Empty | Node({l: t, v: elt, r: t, h: int}) - - /* Sets are represented by balanced binary trees (the heights of the - children differ by at most 2 */ - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - /* Creates a new node with left son l, value v and right son r. - We must have all elements of l < v < all elements of r. - l and r must be balanced and | height l - height r | <= 2. - Inline expansion of height for better speed. */ - - let create = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - /* Same as create, but performs one step of rebalancing if necessary. - Assumes l and r balanced and | height l - height r | <= 3. - Inline expansion of create for better speed in the most frequent case - where no rebalancing is required. */ - - let bal = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Set.bal") - | Node({l: ll, v: lv, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, create(lr, v, r)) - } else { - switch lr { - | Empty => invalid_arg("Set.bal") - | Node({l: lrl, v: lrv, r: lrr}) => create(create(ll, lv, lrl), lrv, create(lrr, v, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Set.bal") - | Node({l: rl, v: rv, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, v, rl), rv, rr) - } else { - switch rl { - | Empty => invalid_arg("Set.bal") - | Node({l: rll, v: rlv, r: rlr}) => create(create(l, v, rll), rlv, create(rlr, rv, rr)) - } - } - } - } else { - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - /* Insertion of one element */ - - let rec add = (x, param) => - switch param { - | Empty => Node({l: Empty, v: x, r: Empty, h: 1}) - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - t - } else if c < 0 { - let ll = add(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = add(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let singleton = x => Node({l: Empty, v: x, r: Empty, h: 1}) - - /* Beware: those two functions assume that the added v is *strictly* - smaller (or bigger) than all the present elements in the tree; it - does not test for equality with the current min (or max) element. - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(add_min_element(x, l), v, r) - } - - let rec add_max_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(l, v, add_max_element(x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, r) => - switch (l, r) { - | (Empty, _) => add_min_element(v, r) - | (_, Empty) => add_max_element(v, l) - | (Node({l: ll, v: lv, r: lr, h: lh}), Node({l: rl, v: rv, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, join(lr, v, r)) - } else if rh > lh + 2 { - bal(join(l, v, rl), rv, rr) - } else { - create(l, v, r) - } - } - - /* Smallest and greatest element of a set */ - - let rec min_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v}) => v - | Node({l}) => min_elt(l) - } - - let rec min_elt_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v}) => Some(v) - | Node({l}) => min_elt_opt(l) - } - - let rec max_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({v, r: Empty}) => v - | Node({r}) => max_elt(r) - } - - let rec max_elt_opt = param => - switch param { - | Empty => None - | Node({v, r: Empty}) => Some(v) - | Node({r}) => max_elt_opt(r) - } - - /* Remove the smallest element of the given set */ - - let rec remove_min_elt = param => - switch param { - | Empty => invalid_arg("Set.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, r}) => bal(remove_min_elt(l), v, r) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - Assume | height l - height r | <= 2. */ - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => bal(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => join(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Splitting. split x s returns a triple (l, present, r) where - - l is the set of elements of s that are < x - - r is the set of elements of s that are > x - - present is false if s contains no element equal to x, - or true if s contains an element equal to x. */ - - let rec split = (x, param) => - switch param { - | Empty => (Empty, false, Empty) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, true, r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, lr), pres, rr) - } - } - - /* Implementation of the set operations */ - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = remove(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let rec union = (s1, s2) => - switch (s1, s2) { - | (Empty, t2) => t2 - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1, h: h1}), Node({l: l2, v: v2, r: r2, h: h2})) => - if h1 >= h2 { - if h2 == 1 { - add(v2, s1) - } else { - let (l2, _, r2) = split(v1, s2) - join(union(l1, l2), v1, union(r1, r2)) - } - } else if h1 == 1 { - add(v1, s2) - } else { - let (l1, _, r1) = split(v2, s1) - join(union(l1, l2), v2, union(r1, r2)) - } - } - - let rec inter = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (_, Empty) => Empty - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => concat(inter(l1, l2), inter(r1, r2)) - | (l2, true, r2) => join(inter(l1, l2), v1, inter(r1, r2)) - } - } - - let rec diff = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => join(diff(l1, l2), v1, diff(r1, r2)) - | (l2, true, r2) => concat(diff(l1, l2), diff(r1, r2)) - } - } - - type rec enumeration = End | More(elt, t, enumeration) - - let rec cons_enum = (s, e) => - switch s { - | Empty => e - | Node({l, v, r}) => cons_enum(l, More(v, r, e)) - } - - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, r1, e1), More(v2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - - let compare = (s1, s2) => compare_aux(cons_enum(s1, End), cons_enum(s2, End)) - - let equal = (s1, s2) => compare(s1, s2) == 0 - - let rec subset = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => true - | (_, Empty) => false - | (Node({l: l1, v: v1, r: r1}), Node({l: l2, v: v2, r: r2}) as t2) => - let c = Ord.compare(v1, v2) - if c == 0 { - subset(l1, l2) && subset(r1, r2) - } else if c < 0 { - subset(Node({l: l1, v: v1, r: Empty, h: 0}), l2) && subset(r1, t2) - } else { - subset(Node({l: Empty, v: v1, r: r1, h: 0}), r2) && subset(l1, t2) - } - } - - let rec iter = (f, param) => - switch param { - | Empty => () - | Node({l, v, r}) => - iter(f, l) - f(v) - iter(f, r) - } - - let rec fold = (f, s, accu) => - switch s { - | Empty => accu - | Node({l, v, r}) => fold(f, r, f(v, fold(f, l, accu))) - } - - let rec for_all = (p, param) => - switch param { - | Empty => true - | Node({l, v, r}) => p(v) && (for_all(p, l) && for_all(p, r)) - } - - let rec exists = (p, param) => - switch param { - | Empty => false - | Node({l, v, r}) => p(v) || (exists(p, l) || exists(p, r)) - } - - let rec filter = (p, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* call [p] in the expected left-to-right order */ - let l' = filter(p, l) - let pv = p(v) - let r' = filter(p, r) - if pv { - if l === l' && r === r' { - t - } else { - join(l', v, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(p, l) - let pv = p(v) - let (rt, rf) = partition(p, r) - if pv { - (join(lt, v, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, rf)) - } - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec elements_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, r}) => elements_aux(list{v, ...elements_aux(accu, r)}, l) - } - - let elements = s => elements_aux(list{}, s) - - let choose = min_elt - - let choose_opt = min_elt_opt - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - v - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first_aux(v0, f, r) - } - } - - let rec find_first = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first(f, r) - } - } - - let rec find_first_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt_aux(v0, f, r) - } - } - - let rec find_first_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt(f, r) - } - } - - let rec find_last_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last_aux(v0, f, l) - } - } - - let rec find_last = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last(f, l) - } - } - - let rec find_last_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt_aux(v0, f, l) - } - } - - let rec find_last_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt(f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(v) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let try_join = (l, v, r) => - /* [join l v r] can only be called when (elements of l < v < - elements of r); use [try_join l v r] when this property may - not hold, but you hope it does hold in the common case */ - if ( - (l == Empty || Ord.compare(max_elt(l), v) < 0) && - (r == Empty || Ord.compare(v, min_elt(r)) < 0) - ) { - join(l, v, r) - } else { - union(l, add(v, r)) - } - - let rec map = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* enforce left-to-right evaluation order */ - let l' = map(f, l) - let v' = f(v) - let r' = map(f, r) - if l === l' && (v === v' && r === r') { - t - } else { - try_join(l', v', r') - } - } - - let of_sorted_list = l => { - let rec sub = (n, l) => - switch (n, l) { - | (0, l) => (Empty, l) - | (1, list{x0, ...l}) => (Node({l: Empty, v: x0, r: Empty, h: 1}), l) - | (2, list{x0, x1, ...l}) => ( - Node({l: Node({l: Empty, v: x0, r: Empty, h: 1}), v: x1, r: Empty, h: 2}), - l, - ) - | (3, list{x0, x1, x2, ...l}) => ( - Node({ - l: Node({l: Empty, v: x0, r: Empty, h: 1}), - v: x1, - r: Node({l: Empty, v: x2, r: Empty, h: 1}), - h: 2, - }), - l, - ) - | (n, l) => - let nl = n / 2 - let (left, l) = sub(nl, l) - switch l { - | list{} => assert(false) - | list{mid, ...l} => - let (right, l) = sub(n - nl - 1, l) - (create(left, mid, right), l) - } - } - - fst(sub(List.length(l), l)) - } - - let of_list = l => - switch l { - | list{} => empty - | list{x0} => singleton(x0) - | list{x0, x1} => add(x1, singleton(x0)) - | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) - | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) - | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) - } -} diff --git a/jscomp/stdlib-406/set.resi b/jscomp/stdlib-406/set.resi deleted file mode 100644 index 7d68f7b7c6..0000000000 --- a/jscomp/stdlib-406/set.resi +++ /dev/null @@ -1,264 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** Sets over ordered types. - - This module implements the set data structure, given a total ordering - function over the set elements. All operations over sets - are purely applicative (no side-effects). - The implementation uses balanced binary trees, and is therefore - reasonably efficient: insertion and membership take time - logarithmic in the size of the set, for instance. - - The {!Make} functor constructs implementations for any type, given a - [compare] function. - For instance: - {[ - module IntPairs = - struct - type t = int * int - let compare (x0,y0) (x1,y1) = - match Pervasives.compare x0 x1 with - 0 -> Pervasives.compare y0 y1 - | c -> c - end - - module PairsSet = Set.Make(IntPairs) - - let m = PairsSet.(empty |> add (2,3) |> add (5,7) |> add (11,13)) - ]} - - This creates a new module [PairsSet], with a new type [PairsSet.t] - of sets of [int * int]. -*/ - -/** Input signature of the functor {!Set.Make}. */ -module type OrderedType = { - /** The type of the set elements. */ - type t - - /** A total ordering function over the set elements. - This is a two-argument function [f] such that - [f e1 e2] is zero if the elements [e1] and [e2] are equal, - [f e1 e2] is strictly negative if [e1] is smaller than [e2], - and [f e1 e2] is strictly positive if [e1] is greater than [e2]. - Example: a suitable ordering function is the generic structural - comparison function {!Pervasives.compare}. */ - let compare: (t, t) => int -} - -/** Output signature of the functor {!Set.Make}. */ -module type S = { - /** The type of the set elements. */ - type elt - - /** The type of sets. */ - type t - - /** The empty set. */ - let empty: t - - /** Test whether a set is empty or not. */ - let is_empty: t => bool - - /** [mem x s] tests whether [x] belongs to the set [s]. */ - let mem: (elt, t) => bool - - /** [add x s] returns a set containing all elements of [s], - plus [x]. If [x] was already in [s], [s] is returned unchanged - (the result of the function is then physically equal to [s]). - @before 4.03 Physical equality was not ensured. */ - let add: (elt, t) => t - - /** [singleton x] returns the one-element set containing only [x]. */ - let singleton: elt => t - - /** [remove x s] returns a set containing all elements of [s], - except [x]. If [x] was not in [s], [s] is returned unchanged - (the result of the function is then physically equal to [s]). - @before 4.03 Physical equality was not ensured. */ - let remove: (elt, t) => t - - /** Set union. */ - let union: (t, t) => t - - /** Set intersection. */ - let inter: (t, t) => t - - /** Set difference. */ - let diff: (t, t) => t - - /** Total ordering between sets. Can be used as the ordering function - for doing sets of sets. */ - let compare: (t, t) => int - - /** [equal s1 s2] tests whether the sets [s1] and [s2] are - equal, that is, contain equal elements. */ - let equal: (t, t) => bool - - /** [subset s1 s2] tests whether the set [s1] is a subset of - the set [s2]. */ - let subset: (t, t) => bool - - /** [iter f s] applies [f] in turn to all elements of [s]. - The elements of [s] are presented to [f] in increasing order - with respect to the ordering over the type of the elements. */ - let iter: (elt => unit, t) => unit - - /** [map f s] is the set whose elements are [f a0],[f a1]... [f - aN], where [a0],[a1]...[aN] are the elements of [s]. - - The elements are passed to [f] in increasing order - with respect to the ordering over the type of the elements. - - If no element of [s] is changed by [f], [s] is returned - unchanged. (If each output of [f] is physically equal to its - input, the returned set is physically equal to [s].) - @since 4.04.0 */ - let map: (elt => elt, t) => t - - /** [fold f s a] computes [(f xN ... (f x2 (f x1 a))...)], - where [x1 ... xN] are the elements of [s], in increasing order. */ - let fold: ((elt, 'a) => 'a, t, 'a) => 'a - - /** [for_all p s] checks if all elements of the set - satisfy the predicate [p]. */ - let for_all: (elt => bool, t) => bool - - /** [exists p s] checks if at least one element of - the set satisfies the predicate [p]. */ - let exists: (elt => bool, t) => bool - - /** [filter p s] returns the set of all elements in [s] - that satisfy predicate [p]. If [p] satisfies every element in [s], - [s] is returned unchanged (the result of the function is then - physically equal to [s]). - @before 4.03 Physical equality was not ensured.*/ - let filter: (elt => bool, t) => t - - /** [partition p s] returns a pair of sets [(s1, s2)], where - [s1] is the set of all the elements of [s] that satisfy the - predicate [p], and [s2] is the set of all the elements of - [s] that do not satisfy [p]. */ - let partition: (elt => bool, t) => (t, t) - - /** Return the number of elements of a set. */ - let cardinal: t => int - - /** Return the list of all elements of the given set. - The returned list is sorted in increasing order with respect - to the ordering [Ord.compare], where [Ord] is the argument - given to {!Set.Make}. */ - let elements: t => list - - /** Return the smallest element of the given set - (with respect to the [Ord.compare] ordering), or raise - [Not_found] if the set is empty. */ - let min_elt: t => elt - - /** Return the smallest element of the given set - (with respect to the [Ord.compare] ordering), or [None] - if the set is empty. - @since 4.05 - */ - let min_elt_opt: t => option - - /** Same as {!Set.S.min_elt}, but returns the largest element of the - given set. */ - let max_elt: t => elt - - /** Same as {!Set.S.min_elt_opt}, but returns the largest element of the - given set. - @since 4.05 - */ - let max_elt_opt: t => option - - /** Return one element of the given set, or raise [Not_found] if - the set is empty. Which element is chosen is unspecified, - but equal elements will be chosen for equal sets. */ - let choose: t => elt - - /** Return one element of the given set, or [None] if - the set is empty. Which element is chosen is unspecified, - but equal elements will be chosen for equal sets. - @since 4.05 - */ - let choose_opt: t => option - - /** [split x s] returns a triple [(l, present, r)], where - [l] is the set of elements of [s] that are - strictly less than [x]; - [r] is the set of elements of [s] that are - strictly greater than [x]; - [present] is [false] if [s] contains no element equal to [x], - or [true] if [s] contains an element equal to [x]. */ - let split: (elt, t) => (t, bool, t) - - /** [find x s] returns the element of [s] equal to [x] (according - to [Ord.compare]), or raise [Not_found] if no such element - exists. - @since 4.01.0 */ - let find: (elt, t) => elt - - /** [find_opt x s] returns the element of [s] equal to [x] (according - to [Ord.compare]), or [None] if no such element - exists. - @since 4.05 */ - let find_opt: (elt, t) => option - - /** [find_first f s], where [f] is a monotonically increasing function, - returns the lowest element [e] of [s] such that [f e], - or raises [Not_found] if no such element exists. - - For example, [find_first (fun e -> Ord.compare e x >= 0) s] will return - the first element [e] of [s] where [Ord.compare e x >= 0] (intuitively: - [e >= x]), or raise [Not_found] if [x] is greater than any element of - [s]. - - @since 4.05 - */ - let find_first: (elt => bool, t) => elt - - /** [find_first_opt f s], where [f] is a monotonically increasing function, - returns an option containing the lowest element [e] of [s] such that - [f e], or [None] if no such element exists. - @since 4.05 - */ - let find_first_opt: (elt => bool, t) => option - - /** [find_last f s], where [f] is a monotonically decreasing function, - returns the highest element [e] of [s] such that [f e], - or raises [Not_found] if no such element exists. - @since 4.05 - */ - let find_last: (elt => bool, t) => elt - - /** [find_last_opt f s], where [f] is a monotonically decreasing function, - returns an option containing the highest element [e] of [s] such that - [f e], or [None] if no such element exists. - @since 4.05 - */ - let find_last_opt: (elt => bool, t) => option - - /** [of_list l] creates a set from a list of elements. - This is usually more efficient than folding [add] over the list, - except perhaps for lists with many duplicated elements. - @since 4.02.0 */ - let of_list: list => t -} - -/** Functor building an implementation of the set structure - given a totally ordered type. */ -module Make: (Ord: OrderedType) => (S with type elt = Ord.t) diff --git a/jscomp/stdlib-406/setLabels.res b/jscomp/stdlib-406/setLabels.res deleted file mode 100644 index 4e0ed5e2c8..0000000000 --- a/jscomp/stdlib-406/setLabels.res +++ /dev/null @@ -1,711 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/* Sets over ordered types */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type elt - type t - let empty: t - let is_empty: t => bool - let mem: (elt, t) => bool - let add: (elt, t) => t - let singleton: elt => t - let remove: (elt, t) => t - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let compare: (t, t) => int - let equal: (t, t) => bool - let subset: (t, t) => bool - let iter: (~f: elt => unit, t) => unit - let map: (~f: elt => elt, t) => t - let fold: (~f: (elt, 'a) => 'a, t, ~init: 'a) => 'a - let for_all: (~f: elt => bool, t) => bool - let exists: (~f: elt => bool, t) => bool - let filter: (~f: elt => bool, t) => t - let partition: (~f: elt => bool, t) => (t, t) - let cardinal: t => int - let elements: t => list - let min_elt: t => elt - let min_elt_opt: t => option - let max_elt: t => elt - let max_elt_opt: t => option - let choose: t => elt - let choose_opt: t => option - let split: (elt, t) => (t, bool, t) - let find: (elt, t) => elt - let find_opt: (elt, t) => option - let find_first: (~f: elt => bool, t) => elt - let find_first_opt: (~f: elt => bool, t) => option - let find_last: (~f: elt => bool, t) => elt - let find_last_opt: (~f: elt => bool, t) => option - let of_list: list => t -} - -module Make = (Ord: OrderedType) => { - type elt = Ord.t - type rec t = Empty | Node({l: t, v: elt, r: t, h: int}) - - /* Sets are represented by balanced binary trees (the heights of the - children differ by at most 2 */ - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - /* Creates a new node with left son l, value v and right son r. - We must have all elements of l < v < all elements of r. - l and r must be balanced and | height l - height r | <= 2. - Inline expansion of height for better speed. */ - - let create = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - /* Same as create, but performs one step of rebalancing if necessary. - Assumes l and r balanced and | height l - height r | <= 3. - Inline expansion of create for better speed in the most frequent case - where no rebalancing is required. */ - - let bal = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Set.bal") - | Node({l: ll, v: lv, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, create(lr, v, r)) - } else { - switch lr { - | Empty => invalid_arg("Set.bal") - | Node({l: lrl, v: lrv, r: lrr}) => create(create(ll, lv, lrl), lrv, create(lrr, v, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Set.bal") - | Node({l: rl, v: rv, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, v, rl), rv, rr) - } else { - switch rl { - | Empty => invalid_arg("Set.bal") - | Node({l: rll, v: rlv, r: rlr}) => create(create(l, v, rll), rlv, create(rlr, rv, rr)) - } - } - } - } else { - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - /* Insertion of one element */ - - let rec add = (x, param) => - switch param { - | Empty => Node({l: Empty, v: x, r: Empty, h: 1}) - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - t - } else if c < 0 { - let ll = add(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = add(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let singleton = x => Node({l: Empty, v: x, r: Empty, h: 1}) - - /* Beware: those two functions assume that the added v is *strictly* - smaller (or bigger) than all the present elements in the tree; it - does not test for equality with the current min (or max) element. - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(add_min_element(x, l), v, r) - } - - let rec add_max_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(l, v, add_max_element(x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, r) => - switch (l, r) { - | (Empty, _) => add_min_element(v, r) - | (_, Empty) => add_max_element(v, l) - | (Node({l: ll, v: lv, r: lr, h: lh}), Node({l: rl, v: rv, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, join(lr, v, r)) - } else if rh > lh + 2 { - bal(join(l, v, rl), rv, rr) - } else { - create(l, v, r) - } - } - - /* Smallest and greatest element of a set */ - - let rec min_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v}) => v - | Node({l}) => min_elt(l) - } - - let rec min_elt_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v}) => Some(v) - | Node({l}) => min_elt_opt(l) - } - - let rec max_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({v, r: Empty}) => v - | Node({r}) => max_elt(r) - } - - let rec max_elt_opt = param => - switch param { - | Empty => None - | Node({v, r: Empty}) => Some(v) - | Node({r}) => max_elt_opt(r) - } - - /* Remove the smallest element of the given set */ - - let rec remove_min_elt = param => - switch param { - | Empty => invalid_arg("Set.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, r}) => bal(remove_min_elt(l), v, r) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - Assume | height l - height r | <= 2. */ - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => bal(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => join(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Splitting. split x s returns a triple (l, present, r) where - - l is the set of elements of s that are < x - - r is the set of elements of s that are > x - - present is false if s contains no element equal to x, - or true if s contains an element equal to x. */ - - let rec split = (x, param) => - switch param { - | Empty => (Empty, false, Empty) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, true, r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, lr), pres, rr) - } - } - - /* Implementation of the set operations */ - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = remove(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let rec union = (s1, s2) => - switch (s1, s2) { - | (Empty, t2) => t2 - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1, h: h1}), Node({l: l2, v: v2, r: r2, h: h2})) => - if h1 >= h2 { - if h2 == 1 { - add(v2, s1) - } else { - let (l2, _, r2) = split(v1, s2) - join(union(l1, l2), v1, union(r1, r2)) - } - } else if h1 == 1 { - add(v1, s2) - } else { - let (l1, _, r1) = split(v2, s1) - join(union(l1, l2), v2, union(r1, r2)) - } - } - - let rec inter = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (_, Empty) => Empty - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => concat(inter(l1, l2), inter(r1, r2)) - | (l2, true, r2) => join(inter(l1, l2), v1, inter(r1, r2)) - } - } - - let rec diff = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => join(diff(l1, l2), v1, diff(r1, r2)) - | (l2, true, r2) => concat(diff(l1, l2), diff(r1, r2)) - } - } - - type rec enumeration = End | More(elt, t, enumeration) - - let rec cons_enum = (s, e) => - switch s { - | Empty => e - | Node({l, v, r}) => cons_enum(l, More(v, r, e)) - } - - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, r1, e1), More(v2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - - let compare = (s1, s2) => compare_aux(cons_enum(s1, End), cons_enum(s2, End)) - - let equal = (s1, s2) => compare(s1, s2) == 0 - - let rec subset = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => true - | (_, Empty) => false - | (Node({l: l1, v: v1, r: r1}), Node({l: l2, v: v2, r: r2}) as t2) => - let c = Ord.compare(v1, v2) - if c == 0 { - subset(l1, l2) && subset(r1, r2) - } else if c < 0 { - subset(Node({l: l1, v: v1, r: Empty, h: 0}), l2) && subset(r1, t2) - } else { - subset(Node({l: Empty, v: v1, r: r1, h: 0}), r2) && subset(l1, t2) - } - } - - let rec iter = (~f, param) => - switch param { - | Empty => () - | Node({l, v, r}) => - iter(~f, l) - f(v) - iter(~f, r) - } - - let rec fold = (~f, s, ~init as accu) => - switch s { - | Empty => accu - | Node({l, v, r}) => fold(~f, r, ~init=f(v, fold(~f, l, ~init=accu))) - } - - let rec for_all = (~f as p, param) => - switch param { - | Empty => true - | Node({l, v, r}) => p(v) && (for_all(~f=p, l) && for_all(~f=p, r)) - } - - let rec exists = (~f as p, param) => - switch param { - | Empty => false - | Node({l, v, r}) => p(v) || (exists(~f=p, l) || exists(~f=p, r)) - } - - let rec filter = (~f as p, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* call [p] in the expected left-to-right order */ - let l' = filter(~f=p, l) - let pv = p(v) - let r' = filter(~f=p, r) - if pv { - if l === l' && r === r' { - t - } else { - join(l', v, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (~f as p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(~f=p, l) - let pv = p(v) - let (rt, rf) = partition(~f=p, r) - if pv { - (join(lt, v, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, rf)) - } - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec elements_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, r}) => elements_aux(list{v, ...elements_aux(accu, r)}, l) - } - - let elements = s => elements_aux(list{}, s) - - let choose = min_elt - - let choose_opt = min_elt_opt - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - v - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first_aux(v0, f, r) - } - } - - let rec find_first = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first(~f, r) - } - } - - let rec find_first_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt_aux(v0, f, r) - } - } - - let rec find_first_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt(~f, r) - } - } - - let rec find_last_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last_aux(v0, f, l) - } - } - - let rec find_last = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last(~f, l) - } - } - - let rec find_last_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt_aux(v0, f, l) - } - } - - let rec find_last_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt(~f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(v) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let try_join = (l, v, r) => - /* [join l v r] can only be called when (elements of l < v < - elements of r); use [try_join l v r] when this property may - not hold, but you hope it does hold in the common case */ - if ( - (l == Empty || Ord.compare(max_elt(l), v) < 0) && - (r == Empty || Ord.compare(v, min_elt(r)) < 0) - ) { - join(l, v, r) - } else { - union(l, add(v, r)) - } - - let rec map = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* enforce left-to-right evaluation order */ - let l' = map(~f, l) - let v' = f(v) - let r' = map(~f, r) - if l === l' && (v === v' && r === r') { - t - } else { - try_join(l', v', r') - } - } - - let of_sorted_list = l => { - let rec sub = (n, l) => - switch (n, l) { - | (0, l) => (Empty, l) - | (1, list{x0, ...l}) => (Node({l: Empty, v: x0, r: Empty, h: 1}), l) - | (2, list{x0, x1, ...l}) => ( - Node({l: Node({l: Empty, v: x0, r: Empty, h: 1}), v: x1, r: Empty, h: 2}), - l, - ) - | (3, list{x0, x1, x2, ...l}) => ( - Node({ - l: Node({l: Empty, v: x0, r: Empty, h: 1}), - v: x1, - r: Node({l: Empty, v: x2, r: Empty, h: 1}), - h: 2, - }), - l, - ) - | (n, l) => - let nl = n / 2 - let (left, l) = sub(nl, l) - switch l { - | list{} => assert(false) - | list{mid, ...l} => - let (right, l) = sub(n - nl - 1, l) - (create(left, mid, right), l) - } - } - - fst(sub(List.length(l), l)) - } - - let of_list = l => - switch l { - | list{} => empty - | list{x0} => singleton(x0) - | list{x0, x1} => add(x1, singleton(x0)) - | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) - | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) - | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) - } -} diff --git a/jscomp/stdlib-406/stack.res b/jscomp/stdlib-406/stack.res deleted file mode 100644 index ee13834b0f..0000000000 --- a/jscomp/stdlib-406/stack.res +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -type t<'a> = {mutable c: list<'a>, mutable len: int} - -exception Empty - -let create = () => {c: list{}, len: 0} - -let clear = s => { - s.c = list{} - s.len = 0 -} - -let copy = s => {c: s.c, len: s.len} - -let push = (x, s) => { - s.c = list{x, ...s.c} - s.len = s.len + 1 -} - -let pop = s => - switch s.c { - | list{hd, ...tl} => - s.c = tl - s.len = s.len - 1 - hd - | list{} => raise(Empty) - } - -let top = s => - switch s.c { - | list{hd, ..._} => hd - | list{} => raise(Empty) - } - -let is_empty = s => s.c == list{} - -let length = s => s.len - -let iter = (f, s) => List.iter(f, s.c) - -let fold = (f, acc, s) => List.fold_left(f, acc, s.c) diff --git a/jscomp/stdlib-406/stack.resi b/jscomp/stdlib-406/stack.resi deleted file mode 100644 index 6acaaa7a03..0000000000 --- a/jscomp/stdlib-406/stack.resi +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. */ -/* */ -/* All rights reserved. This file is distributed under the terms of */ -/* the GNU Lesser General Public License version 2.1, with the */ -/* special exception on linking described in the file LICENSE. */ -/* */ -/* ************************************************************************ */ - -/*** Last-in first-out stacks. - - This module implements stacks (LIFOs), with in-place modification. -*/ - -/** The type of stacks containing elements of type ['a]. */ -type t<'a> - -/** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. */ exception Empty - -/** Return a new stack, initially empty. */ -let create: unit => t<'a> - -/** [push x s] adds the element [x] at the top of stack [s]. */ -let push: ('a, t<'a>) => unit - -/** [pop s] removes and returns the topmost element in stack [s], - or raises {!Empty} if the stack is empty. */ -let pop: t<'a> => 'a - -/** [top s] returns the topmost element in stack [s], - or raises {!Empty} if the stack is empty. */ -let top: t<'a> => 'a - -/** Discard all elements from a stack. */ -let clear: t<'a> => unit - -/** Return a copy of the given stack. */ -let copy: t<'a> => t<'a> - -/** Return [true] if the given stack is empty, [false] otherwise. */ -let is_empty: t<'a> => bool - -/** Return the number of elements in a stack. Time complexity O(1) */ -let length: t<'a> => int - -/** [iter f s] applies [f] in turn to all elements of [s], - from the element at the top of the stack to the element at the - bottom of the stack. The stack itself is unchanged. */ -let iter: ('a => unit, t<'a>) => unit - -/** [fold f accu s] is [(f (... (f (f accu x1) x2) ...) xn)] - where [x1] is the top of the stack, [x2] the second element, - and [xn] the bottom element. The stack is unchanged. - @since 4.03 */ -let fold: (('b, 'a) => 'b, 'b, t<'a>) => 'b diff --git a/jscomp/test/a.js b/jscomp/test/a.js index d856702bfe..1eb4cada7a 100644 --- a/jscomp/test/a.js +++ b/jscomp/test/a.js @@ -1,2 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ +'use strict'; + + +function Make(U) { + return { + v: U.compare + }; +} + +exports.Make = Make; +/* No side effect */ diff --git a/jscomp/test/a.res b/jscomp/test/a.res index dbfb1567f4..d6dfa0c868 100644 --- a/jscomp/test/a.res +++ b/jscomp/test/a.res @@ -1,3 +1,12 @@ +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + let v = U.compare +} + include ( { module M = ( @@ -11,20 +20,16 @@ include ( let add = (x, y) => x + y }) + open Belt + include List module N = List let v = N.length - module Make = (U: Set.OrderedType) => { - include U - let v = compare + module Make = (U: OrderedType) => { + let v = U.compare } - module X = Make(String) module U = Make(Test_order) - - include N - /* let v = "xhg" */ - /* let () = v.[0] <- 'a' */ }: {} ) diff --git a/jscomp/test/basic_module_test.js b/jscomp/test/basic_module_test.js deleted file mode 100644 index cc66bb5a9e..0000000000 --- a/jscomp/test/basic_module_test.js +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Offset = require("./offset.js"); -let Pr6726 = require("./pr6726.js"); -let Mt_global = require("./mt_global.js"); - -let count = { - contents: 0 -}; - -function test(set) { - count.contents = Offset.$$Set.cardinal(set) + count.contents | 0; -} - -test(Offset.M.$$Set.singleton("42")); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(f, a, b) { - Mt_global.collect_eq(test_id, suites, f, a, b); -} - -eq("File \"basic_module_test.res\", line 40, characters 12-19", count.contents, 1); - -Mt.from_pair_suites("Basic_module_test", suites.contents); - -/* Not a pure module */ diff --git a/jscomp/test/basic_module_test.res b/jscomp/test/basic_module_test.res deleted file mode 100644 index 2fecf98317..0000000000 --- a/jscomp/test/basic_module_test.res +++ /dev/null @@ -1,42 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Nagoya University */ -/* */ -/* Copyright 2014 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the Q Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -/* PR#6435 */ -let count = ref(0) - -module F = ( - M: { - type t - module Set: Set.S with type elt = t - }, -) => { - let test = set => count := M.Set.cardinal(set) + count.contents -} - -module M = F(Offset) - -let () = M.test(Offset.M.Set.singleton("42")) -/* - here we assume value access does not have side effect - however, the module should be included - since it may contain side effect unless we - analyze it does not have side effect -*/ -let v = Pr6726.Test.v - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (f, a, b) => Mt_global.collect_eq(test_id, suites, f, a, b) - -let () = eq(__LOC__, count.contents, 1) - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/basic_module_test.resi b/jscomp/test/basic_module_test.resi deleted file mode 100644 index e7bcc98fab..0000000000 --- a/jscomp/test/basic_module_test.resi +++ /dev/null @@ -1 +0,0 @@ -/* val v : int */ diff --git a/jscomp/test/block_alias_test.js b/jscomp/test/block_alias_test.js index 51dc8b4193..4933f54cbe 100644 --- a/jscomp/test/block_alias_test.js +++ b/jscomp/test/block_alias_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -44,15 +44,15 @@ let N = { let Caml_obj$1 = {}; -let List$1 = {}; +let List = {}; let V = { - List: List$1 + List: List }; let f = Caml_obj.equal; -eq("File \"block_alias_test.res\", line 27, characters 3-10", List.length({ +eq("File \"block_alias_test.res\", line 27, characters 3-10", Belt_List.length({ hd: 1, tl: { hd: 2, @@ -70,7 +70,7 @@ eq("File \"block_alias_test.res\", line 29, characters 3-10", v0, v1); Mt.from_pair_suites("Block_alias_test", suites.contents); -let h = List.length; +let h = Belt_List.length; exports.suites = suites; exports.test_id = test_id; diff --git a/jscomp/test/block_alias_test.res b/jscomp/test/block_alias_test.res index fc6b264bc0..2e0d94b438 100644 --- a/jscomp/test/block_alias_test.res +++ b/jscomp/test/block_alias_test.res @@ -22,7 +22,7 @@ module V = { } let f = (a, b) => a == b -let h = List.length +let h = Belt.List.length eq(__LOC__, h(list{1, 2}), 2) b(__LOC__, f(v0, A(0, 1))) diff --git a/jscomp/test/build.ninja b/jscomp/test/build.ninja index c32bf9c2c1..2eac2f30d0 100644 --- a/jscomp/test/build.ninja +++ b/jscomp/test/build.ninja @@ -61,8 +61,6 @@ o test/attr_test.cmi test/attr_test.cmj : cc test/attr_test.res | $bsc $stdlib r o test/b.cmi test/b.cmj : cc test/b.res | $bsc $stdlib runtime o test/bal_set_mini.cmi test/bal_set_mini.cmj : cc test/bal_set_mini.res | $bsc $stdlib runtime o test/bang_primitive.cmi test/bang_primitive.cmj : cc test/bang_primitive.res | $bsc $stdlib runtime -o test/basic_module_test.cmj : cc_cmi test/basic_module_test.res | test/basic_module_test.cmi test/mt.cmj test/mt_global.cmj test/offset.cmj test/pr6726.cmj $bsc $stdlib runtime -o test/basic_module_test.cmi : cc test/basic_module_test.resi | $bsc $stdlib runtime o test/bb.cmi test/bb.cmj : cc test/bb.res | $bsc $stdlib runtime o test/bdd.cmi test/bdd.cmj : cc test/bdd.res | $bsc $stdlib runtime o test/belt_float_ntest.cmi test/belt_float_ntest.cmj : cc test/belt_float_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime @@ -111,7 +109,6 @@ o test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj : cc test/class_type o test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj : cc test/coercion_module_alias_test.res | $bsc $stdlib runtime o test/compare_test.cmi test/compare_test.cmj : cc test/compare_test.res | $bsc $stdlib runtime o test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj : cc test/complete_parmatch_test.res | $bsc $stdlib runtime -o test/complex_test.cmi test/complex_test.cmj : cc test/complex_test.res | test/mt.cmj $bsc $stdlib runtime o test/complex_while_loop.cmi test/complex_while_loop.cmj : cc test/complex_while_loop.res | $bsc $stdlib runtime o test/condition_compilation_test.cmi test/condition_compilation_test.cmj : cc test/condition_compilation_test.res | test/mt.cmj $bsc $stdlib runtime o test/config1_test.cmi test/config1_test.cmj : cc test/config1_test.res | $bsc $stdlib runtime @@ -380,14 +377,11 @@ o test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow o test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.res | $bsc $stdlib runtime o test/lazy_test.cmi test/lazy_test.cmj : cc test/lazy_test.res | test/mt.cmj $bsc $stdlib runtime o test/lib_js_test.cmi test/lib_js_test.cmj : cc test/lib_js_test.res | test/mt.cmj $bsc $stdlib runtime -o test/libqueue_test.cmi test/libqueue_test.cmj : cc test/libqueue_test.res | $bsc $stdlib runtime o test/limits_test.cmi test/limits_test.cmj : cc test/limits_test.res | test/mt.cmj $bsc $stdlib runtime -o test/list_stack.cmi test/list_stack.cmj : cc test/list_stack.res | $bsc $stdlib runtime o test/list_test.cmi test/list_test.cmj : cc test/list_test.res | test/mt.cmj $bsc $stdlib runtime o test/local_exception_test.cmi test/local_exception_test.cmj : cc test/local_exception_test.res | $bsc $stdlib runtime o test/loop_regression_test.cmi test/loop_regression_test.cmj : cc test/loop_regression_test.res | test/mt.cmj $bsc $stdlib runtime o test/map_find_test.cmi test/map_find_test.cmj : cc test/map_find_test.res | test/mt.cmj $bsc $stdlib runtime -o test/map_test.cmi test/map_test.cmj : cc test/map_test.res | test/mt.cmj $bsc $stdlib runtime o test/mario_game.cmi test/mario_game.cmj : cc test/mario_game.res | $bsc $stdlib runtime o test/meth_annotation.cmi test/meth_annotation.cmj : cc test/meth_annotation.res | $bsc $stdlib runtime o test/method_name_test.cmi test/method_name_test.cmj : cc test/method_name_test.res | test/mt.cmj $bsc $stdlib runtime @@ -449,7 +443,6 @@ o test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj : cc test/prepend_data_ffi o test/primitive_reg_test.cmi test/primitive_reg_test.cmj : cc test/primitive_reg_test.res | $bsc $stdlib runtime o test/print_alpha_test.cmi test/print_alpha_test.cmj : cc test/print_alpha_test.res | test/mt.cmj $bsc $stdlib runtime o test/queue_402.cmi test/queue_402.cmj : cc test/queue_402.res | $bsc $stdlib runtime -o test/queue_test.cmi test/queue_test.cmj : cc test/queue_test.res | test/mt.cmj test/queue_402.cmj $bsc $stdlib runtime o test/raw_output_test.cmi test/raw_output_test.cmj : cc test/raw_output_test.res | $bsc $stdlib runtime o test/raw_pure_test.cmi test/raw_pure_test.cmj : cc test/raw_pure_test.res | $bsc $stdlib runtime o test/rbset.cmi test/rbset.cmj : cc test/rbset.res | $bsc $stdlib runtime @@ -496,12 +489,9 @@ o test/side_effect.cmi test/side_effect.cmj : cc test/side_effect.res | $bsc $st o test/side_effect2.cmi test/side_effect2.cmj : cc test/side_effect2.res | $bsc $stdlib runtime o test/side_effect_free.cmi test/side_effect_free.cmj : cc test/side_effect_free.res | $bsc $stdlib runtime o test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj : cc test/simplify_lambda_632o.res | $bsc $stdlib runtime -o test/single_module_alias.cmi test/single_module_alias.cmj : cc test/single_module_alias.res | $bsc $stdlib runtime o test/singular_unit_test.cmi test/singular_unit_test.cmj : cc test/singular_unit_test.res | $bsc $stdlib runtime o test/small_inline_test.cmi test/small_inline_test.cmj : cc test/small_inline_test.res | $bsc $stdlib runtime o test/splice_test.cmi test/splice_test.cmj : cc test/splice_test.res | test/mt.cmj $bsc $stdlib runtime -o test/stack_comp_test.cmi test/stack_comp_test.cmj : cc test/stack_comp_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/stack_test.cmi test/stack_test.cmj : cc test/stack_test.res | test/mt.cmj $bsc $stdlib runtime o test/string_bound_get_test.cmi test/string_bound_get_test.cmj : cc test/string_bound_get_test.res | $bsc $stdlib runtime o test/string_constant_compare.cmi test/string_constant_compare.cmj : cc test/string_constant_compare.res | $bsc $stdlib runtime o test/string_set.cmi test/string_set.cmj : cc test/string_set.res | test/set_gen.cmj $bsc $stdlib runtime @@ -516,7 +506,6 @@ o test/tagged_template_test.cmi test/tagged_template_test.cmj : cc test/tagged_t o test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj : cc test/tailcall_inline_test.res | test/mt.cmj $bsc $stdlib runtime o test/template.cmi test/template.cmj : cc test/template.res | $bsc $stdlib runtime o test/test2.cmi test/test2.cmj : cc test/test2.res | $bsc $stdlib runtime -o test/test_alias.cmi test/test_alias.cmj : cc test/test_alias.res | test/test_global_print.cmj $bsc $stdlib runtime o test/test_ari.cmi test/test_ari.cmj : cc test/test_ari.res | $bsc $stdlib runtime o test/test_array.cmi test/test_array.cmj : cc test/test_array.res | $bsc $stdlib runtime o test/test_array_append.cmi test/test_array_append.cmj : cc test/test_array_append.res | $bsc $stdlib runtime @@ -543,26 +532,24 @@ o test/test_ffi.cmi test/test_ffi.cmj : cc test/test_ffi.res | $bsc $stdlib runt o test/test_fib.cmi test/test_fib.cmj : cc test/test_fib.res | $bsc $stdlib runtime o test/test_for_loop.cmi test/test_for_loop.cmj : cc test/test_for_loop.res | $bsc $stdlib runtime o test/test_for_map.cmi test/test_for_map.cmj : cc test/test_for_map.res | $bsc $stdlib runtime -o test/test_for_map2.cmi test/test_for_map2.cmj : cc test/test_for_map2.res | test/int_map.cmj $bsc $stdlib runtime +o test/test_for_map2.cmi test/test_for_map2.cmj : cc test/test_for_map2.res | $bsc $stdlib runtime o test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj : cc test/test_functor_dead_code.res | $bsc $stdlib runtime o test/test_generative_module.cmi test/test_generative_module.cmj : cc test/test_generative_module.res | $bsc $stdlib runtime -o test/test_global_print.cmi test/test_global_print.cmj : cc test/test_global_print.res | $bsc $stdlib runtime o test/test_google_closure.cmi test/test_google_closure.cmj : cc test/test_google_closure.res | $bsc $stdlib runtime o test/test_include.cmi test/test_include.cmj : cc test/test_include.res | test/test_order.cmj $bsc $stdlib runtime o test/test_incomplete.cmi test/test_incomplete.cmj : cc test/test_incomplete.res | $bsc $stdlib runtime o test/test_incr_ref.cmi test/test_incr_ref.cmj : cc test/test_incr_ref.res | $bsc $stdlib runtime o test/test_int_map_find.cmi test/test_int_map_find.cmj : cc test/test_int_map_find.res | $bsc $stdlib runtime o test/test_is_js.cmi test/test_is_js.cmj : cc test/test_is_js.res | test/mt.cmj $bsc $stdlib runtime -o test/test_js_ffi.cmi test/test_js_ffi.cmj : cc test/test_js_ffi.res | $bsc $stdlib runtime +o test/test_js_ffi.cmi test/test_js_ffi.cmj : cc test/test_js_ffi.res | test/test_order.cmj $bsc $stdlib runtime o test/test_let.cmi test/test_let.cmj : cc test/test_let.res | $bsc $stdlib runtime o test/test_list.cmi test/test_list.cmj : cc test/test_list.res | $bsc $stdlib runtime o test/test_literal.cmi test/test_literal.cmj : cc test/test_literal.res | $bsc $stdlib runtime o test/test_literals.cmi test/test_literals.cmj : cc test/test_literals.res | $bsc $stdlib runtime o test/test_match_exception.cmi test/test_match_exception.cmj : cc test/test_match_exception.res | $bsc $stdlib runtime -o test/test_mutliple.cmi test/test_mutliple.cmj : cc test/test_mutliple.res | $bsc $stdlib runtime o test/test_nested_let.cmi test/test_nested_let.cmj : cc test/test_nested_let.res | $bsc $stdlib runtime o test/test_nested_print.cmi test/test_nested_print.cmj : cc test/test_nested_print.res | $bsc $stdlib runtime -o test/test_non_export.cmi test/test_non_export.cmj : cc test/test_non_export.res | $bsc $stdlib runtime +o test/test_non_export.cmi test/test_non_export.cmj : cc test/test_non_export.res | test/test_order.cmj $bsc $stdlib runtime o test/test_nullary.cmi test/test_nullary.cmj : cc test/test_nullary.res | $bsc $stdlib runtime o test/test_obj.cmi test/test_obj.cmj : cc test/test_obj.res | $bsc $stdlib runtime o test/test_order.cmi test/test_order.cmj : cc test/test_order.res | $bsc $stdlib runtime @@ -570,7 +557,6 @@ o test/test_order_tailcall.cmi test/test_order_tailcall.cmj : cc test/test_order o test/test_other_exn.cmi test/test_other_exn.cmj : cc test/test_other_exn.res | $bsc $stdlib runtime o test/test_per.cmi test/test_per.cmj : cc test/test_per.res | $bsc $stdlib runtime o test/test_pervasive.cmi test/test_pervasive.cmj : cc test/test_pervasive.res | $bsc $stdlib runtime -o test/test_pervasives2.cmi test/test_pervasives2.cmj : cc test/test_pervasives2.res | $bsc $stdlib runtime o test/test_pervasives3.cmi test/test_pervasives3.cmj : cc test/test_pervasives3.res | $bsc $stdlib runtime o test/test_primitive.cmi test/test_primitive.cmj : cc test/test_primitive.res | $bsc $stdlib runtime o test/test_ramification.cmi test/test_ramification.cmj : cc test/test_ramification.res | $bsc $stdlib runtime @@ -587,7 +573,6 @@ o test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj : cc tes o test/test_simple_ref.cmi test/test_simple_ref.cmj : cc test/test_simple_ref.res | $bsc $stdlib runtime o test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj : cc test/test_simple_tailcall.res | $bsc $stdlib runtime o test/test_small.cmi test/test_small.cmj : cc test/test_small.res | $bsc $stdlib runtime -o test/test_stack.cmi test/test_stack.cmj : cc test/test_stack.res | $bsc $stdlib runtime o test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj : cc test/test_static_catch_ident.res | $bsc $stdlib runtime o test/test_string.cmi test/test_string.cmj : cc test/test_string.res | $bsc $stdlib runtime o test/test_string_case.cmi test/test_string_case.cmj : cc test/test_string_case.res | $bsc $stdlib runtime @@ -638,4 +623,4 @@ o test/update_record_test.cmi test/update_record_test.cmj : cc test/update_recor o test/variant.cmi test/variant.cmj : cc test/variant.res | $bsc $stdlib runtime o test/variantsMatching.cmi test/variantsMatching.cmj : cc test/variantsMatching.res | $bsc $stdlib runtime o test/webpack_config.cmi test/webpack_config.cmj : cc test/webpack_config.res | $bsc $stdlib runtime -o test : phony test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj test/Coercion.cmi test/Coercion.cmj test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj test/DictInference.cmi test/DictInference.cmj test/DictTests.cmi test/DictTests.cmj test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj test/DotDotDot.cmi test/DotDotDot.cmj test/EmptyRecord.cmi test/EmptyRecord.cmj test/ExternalArity.cmi test/ExternalArity.cmj test/FFI.cmi test/FFI.cmj test/Import.cmi test/Import.cmj test/ImportAttributes.cmi test/ImportAttributes.cmj test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj test/RecordCoercion.cmi test/RecordCoercion.cmj test/RecordOrObject.cmi test/RecordOrObject.cmj test/SafePromises.cmi test/SafePromises.cmj test/UncurriedAlways.cmi test/UncurriedAlways.cmj test/UncurriedExternals.cmi test/UncurriedExternals.cmj test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj test/UntaggedVariants.cmi test/UntaggedVariants.cmj test/VariantCoercion.cmi test/VariantCoercion.cmj test/VariantSpreads.cmi test/VariantSpreads.cmj test/a.cmi test/a.cmj test/a_recursive_type.cmi test/a_recursive_type.cmj test/a_scope_bug.cmi test/a_scope_bug.cmj test/abstract_type.cmi test/abstract_type.cmj test/adt_optimize_test.cmi test/adt_optimize_test.cmj test/alias_default_value_test.cmi test/alias_default_value_test.cmj test/alias_test.cmi test/alias_test.cmj test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj test/ari_regress_test.cmi test/ari_regress_test.cmj test/arith_syntax.cmi test/arith_syntax.cmj test/arity.cmi test/arity.cmj test/arity_deopt.cmi test/arity_deopt.cmj test/arity_infer.cmi test/arity_infer.cmj test/array_data_util.cmi test/array_data_util.cmj test/array_safe_get.cmi test/array_safe_get.cmj test/array_subtle_test.cmi test/array_subtle_test.cmj test/as_inline_record_test.cmi test/as_inline_record_test.cmj test/ast_abstract_test.cmi test/ast_abstract_test.cmj test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj test/async_await.cmi test/async_await.cmj test/async_inline.cmi test/async_inline.cmj test/async_inside_loop.cmi test/async_inside_loop.cmj test/attr_test.cmi test/attr_test.cmj test/b.cmi test/b.cmj test/bal_set_mini.cmi test/bal_set_mini.cmj test/bang_primitive.cmi test/bang_primitive.cmj test/basic_module_test.cmi test/basic_module_test.cmj test/bb.cmi test/bb.cmj test/bdd.cmi test/bdd.cmj test/belt_float_ntest.cmi test/belt_float_ntest.cmj test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj test/belt_int_ntest.cmi test/belt_int_ntest.cmj test/belt_internal_test.cmi test/belt_internal_test.cmj test/belt_list_ntest.cmi test/belt_list_ntest.cmj test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj test/bench.cmi test/bench.cmj test/big_enum.cmi test/big_enum.cmj test/big_polyvar_test.cmi test/big_polyvar_test.cmj test/bigint_test.cmi test/bigint_test.cmj test/block_alias_test.cmi test/block_alias_test.cmj test/boolean_test.cmi test/boolean_test.cmj test/bs_abstract_test.cmi test/bs_abstract_test.cmj test/bs_array_test.cmi test/bs_array_test.cmj test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj test/bs_ignore_test.cmi test/bs_ignore_test.cmj test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj test/bs_map_test.cmi test/bs_map_test.cmj test/bs_min_max_test.cmi test/bs_min_max_test.cmj test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj test/bs_qualified.cmi test/bs_qualified.cmj test/bs_queue_test.cmi test/bs_queue_test.cmj test/bs_rest_test.cmi test/bs_rest_test.cmj test/bs_set_int_test.cmi test/bs_set_int_test.cmj test/bs_splice_partial.cmi test/bs_splice_partial.cmj test/bs_stack_test.cmi test/bs_stack_test.cmj test/bs_string_test.cmi test/bs_string_test.cmj test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj test/caml_compare_test.cmi test/caml_compare_test.cmj test/chain_code_test.cmi test/chain_code_test.cmj test/chn_test.cmi test/chn_test.cmj test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj test/compare_test.cmi test/compare_test.cmj test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj test/complex_test.cmi test/complex_test.cmj test/complex_while_loop.cmi test/complex_while_loop.cmj test/condition_compilation_test.cmi test/condition_compilation_test.cmj test/config1_test.cmi test/config1_test.cmj test/console_log_test.cmi test/console_log_test.cmj test/const_block_test.cmi test/const_block_test.cmj test/const_defs.cmi test/const_defs.cmj test/const_defs_test.cmi test/const_defs_test.cmj test/const_test.cmi test/const_test.cmj test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj test/cps_test.cmi test/cps_test.cmj test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj test/custom_error_test.cmi test/custom_error_test.cmj test/debug_keep_test.cmi test/debug_keep_test.cmj test/debug_mode_value.cmi test/debug_mode_value.cmj test/debug_tmp.cmi test/debug_tmp.cmj test/debugger_test.cmi test/debugger_test.cmj test/default_export_test.cmi test/default_export_test.cmj test/defunctor_make_test.cmi test/defunctor_make_test.cmj test/demo_int_map.cmi test/demo_int_map.cmj test/demo_page.cmi test/demo_page.cmj test/demo_pipe.cmi test/demo_pipe.cmj test/derive_projector_test.cmi test/derive_projector_test.cmj test/directives.cmi test/directives.cmj test/div_by_zero_test.cmi test/div_by_zero_test.cmj test/dollar_escape_test.cmi test/dollar_escape_test.cmj test/earger_curry_test.cmi test/earger_curry_test.cmj test/effect.cmi test/effect.cmj test/epsilon_test.cmi test/epsilon_test.cmj test/equal_box_test.cmi test/equal_box_test.cmj test/equal_exception_test.cmi test/equal_exception_test.cmj test/equal_test.cmi test/equal_test.cmj test/es6_export.cmi test/es6_export.cmj test/es6_import.cmi test/es6_import.cmj test/es6_module_test.cmi test/es6_module_test.cmj test/escape_esmodule.cmi test/escape_esmodule.cmj test/esmodule_ref.cmi test/esmodule_ref.cmj test/event_ffi.cmi test/event_ffi.cmj test/exception_alias.cmi test/exception_alias.cmj test/exception_raise_test.cmi test/exception_raise_test.cmj test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj test/exception_value_test.cmi test/exception_value_test.cmj test/exotic_labels_test.cmi test/exotic_labels_test.cmj test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj test/export_keyword.cmi test/export_keyword.cmj test/ext_array_test.cmi test/ext_array_test.cmj test/ext_pervasives_test.cmi test/ext_pervasives_test.cmj test/extensible_variant_test.cmi test/extensible_variant_test.cmj test/external_ppx.cmi test/external_ppx.cmj test/external_ppx2.cmi test/external_ppx2.cmj test/ffi_arity_test.cmi test/ffi_arity_test.cmj test/ffi_array_test.cmi test/ffi_array_test.cmj test/ffi_js_test.cmi test/ffi_js_test.cmj test/ffi_splice_test.cmi test/ffi_splice_test.cmj test/ffi_test.cmi test/ffi_test.cmj test/fib.cmi test/fib.cmj test/flattern_order_test.cmi test/flattern_order_test.cmj test/flexible_array_test.cmi test/flexible_array_test.cmj test/float_array.cmi test/float_array.cmj test/float_record.cmi test/float_record.cmj test/float_test.cmi test/float_test.cmj test/for_loop_test.cmi test/for_loop_test.cmj test/for_side_effect_test.cmi test/for_side_effect_test.cmj test/format_regression.cmi test/format_regression.cmj test/fun_pattern_match.cmi test/fun_pattern_match.cmj test/function_directives.cmi test/function_directives.cmj test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj test/functor_app_test.cmi test/functor_app_test.cmj test/functor_def.cmi test/functor_def.cmj test/functor_ffi.cmi test/functor_ffi.cmj test/functor_inst.cmi test/functor_inst.cmj test/functors.cmi test/functors.cmj test/gbk.cmi test/gbk.cmj test/gentTypeReTest.cmi test/gentTypeReTest.cmj test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj test/global_mangles.cmi test/global_mangles.cmj test/global_module_alias_test.cmi test/global_module_alias_test.cmj test/google_closure_test.cmi test/google_closure_test.cmj test/gpr496_test.cmi test/gpr496_test.cmj test/gpr_1072.cmi test/gpr_1072.cmj test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj test/gpr_1150.cmi test/gpr_1150.cmj test/gpr_1170.cmi test/gpr_1170.cmj test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj test/gpr_1245_test.cmi test/gpr_1245_test.cmj test/gpr_1268.cmi test/gpr_1268.cmj test/gpr_1409_test.cmi test/gpr_1409_test.cmj test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj test/gpr_1438.cmi test/gpr_1438.cmj test/gpr_1481.cmi test/gpr_1481.cmj test/gpr_1484.cmi test/gpr_1484.cmj test/gpr_1539_test.cmi test/gpr_1539_test.cmj test/gpr_1658_test.cmi test/gpr_1658_test.cmj test/gpr_1667_test.cmi test/gpr_1667_test.cmj test/gpr_1692_test.cmi test/gpr_1692_test.cmj test/gpr_1698_test.cmi test/gpr_1698_test.cmj test/gpr_1701_test.cmi test/gpr_1701_test.cmj test/gpr_1716_test.cmi test/gpr_1716_test.cmj test/gpr_1717_test.cmi test/gpr_1717_test.cmj test/gpr_1728_test.cmi test/gpr_1728_test.cmj test/gpr_1749_test.cmi test/gpr_1749_test.cmj test/gpr_1759_test.cmi test/gpr_1759_test.cmj test/gpr_1760_test.cmi test/gpr_1760_test.cmj test/gpr_1762_test.cmi test/gpr_1762_test.cmj test/gpr_1817_test.cmi test/gpr_1817_test.cmj test/gpr_1822_test.cmi test/gpr_1822_test.cmj test/gpr_1891_test.cmi test/gpr_1891_test.cmj test/gpr_1943_test.cmi test/gpr_1943_test.cmj test/gpr_1946_test.cmi test/gpr_1946_test.cmj test/gpr_2316_test.cmi test/gpr_2316_test.cmj test/gpr_2352_test.cmi test/gpr_2352_test.cmj test/gpr_2413_test.cmi test/gpr_2413_test.cmj test/gpr_2474.cmi test/gpr_2474.cmj test/gpr_2487.cmi test/gpr_2487.cmj test/gpr_2503_test.cmi test/gpr_2503_test.cmj test/gpr_2608_test.cmi test/gpr_2608_test.cmj test/gpr_2614_test.cmi test/gpr_2614_test.cmj test/gpr_2633_test.cmi test/gpr_2633_test.cmj test/gpr_2642_test.cmi test/gpr_2642_test.cmj test/gpr_2682_test.cmi test/gpr_2682_test.cmj test/gpr_2700_test.cmi test/gpr_2700_test.cmj test/gpr_2731_test.cmi test/gpr_2731_test.cmj test/gpr_2789_test.cmi test/gpr_2789_test.cmj test/gpr_2931_test.cmi test/gpr_2931_test.cmj test/gpr_3142_test.cmi test/gpr_3142_test.cmj test/gpr_3154_test.cmi test/gpr_3154_test.cmj test/gpr_3209_test.cmi test/gpr_3209_test.cmj test/gpr_3492_test.cmi test/gpr_3492_test.cmj test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj test/gpr_3519_test.cmi test/gpr_3519_test.cmj test/gpr_3536_test.cmi test/gpr_3536_test.cmj test/gpr_3546_test.cmi test/gpr_3546_test.cmj test/gpr_3548_test.cmi test/gpr_3548_test.cmj test/gpr_3549_test.cmi test/gpr_3549_test.cmj test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj test/gpr_3566_test.cmi test/gpr_3566_test.cmj test/gpr_3595_test.cmi test/gpr_3595_test.cmj test/gpr_3609_test.cmi test/gpr_3609_test.cmj test/gpr_3697_test.cmi test/gpr_3697_test.cmj test/gpr_373_test.cmi test/gpr_373_test.cmj test/gpr_3770_test.cmi test/gpr_3770_test.cmj test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj test/gpr_3852_alias_reify.cmi test/gpr_3852_alias_reify.cmj test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj test/gpr_3865.cmi test/gpr_3865.cmj test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj test/gpr_3875_test.cmi test/gpr_3875_test.cmj test/gpr_3877_test.cmi test/gpr_3877_test.cmj test/gpr_3895_test.cmi test/gpr_3895_test.cmj test/gpr_3897_test.cmi test/gpr_3897_test.cmj test/gpr_3931_test.cmi test/gpr_3931_test.cmj test/gpr_3980_test.cmi test/gpr_3980_test.cmj test/gpr_4025_test.cmi test/gpr_4025_test.cmj test/gpr_4069_test.cmi test/gpr_4069_test.cmj test/gpr_4265_test.cmi test/gpr_4265_test.cmj test/gpr_4274_test.cmi test/gpr_4274_test.cmj test/gpr_4280_test.cmi test/gpr_4280_test.cmj test/gpr_4407_test.cmi test/gpr_4407_test.cmj test/gpr_441.cmi test/gpr_441.cmj test/gpr_4442_test.cmi test/gpr_4442_test.cmj test/gpr_4491_test.cmi test/gpr_4491_test.cmj test/gpr_4494_test.cmi test/gpr_4494_test.cmj test/gpr_4519_test.cmi test/gpr_4519_test.cmj test/gpr_459_test.cmi test/gpr_459_test.cmj test/gpr_4632.cmi test/gpr_4632.cmj test/gpr_4639_test.cmi test/gpr_4639_test.cmj test/gpr_4900_test.cmi test/gpr_4900_test.cmj test/gpr_4924_test.cmi test/gpr_4924_test.cmj test/gpr_4931.cmi test/gpr_4931.cmj test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj test/gpr_5071_test.cmi test/gpr_5071_test.cmj test/gpr_5169_test.cmi test/gpr_5169_test.cmj test/gpr_5218_test.cmi test/gpr_5218_test.cmj test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj test/gpr_5557.cmi test/gpr_5557.cmj test/gpr_5753.cmi test/gpr_5753.cmj test/gpr_658.cmi test/gpr_658.cmj test/gpr_7012_test.cmi test/gpr_7012_test.cmj test/gpr_858_test.cmi test/gpr_858_test.cmj test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj test/gpr_904_test.cmi test/gpr_904_test.cmj test/gpr_974_test.cmi test/gpr_974_test.cmj test/gpr_977_test.cmi test/gpr_977_test.cmj test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj test/gray_code_test.cmi test/gray_code_test.cmj test/guide_for_ext.cmi test/guide_for_ext.cmj test/hash_collision_test.cmi test/hash_collision_test.cmj test/hash_sugar_desugar.cmi test/hash_sugar_desugar.cmj test/hash_test.cmi test/hash_test.cmj test/hello.foo.cmi test/hello.foo.cmj test/hello_res.cmi test/hello_res.cmj test/ignore_test.cmi test/ignore_test.cmj test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj test/import2.cmi test/import2.cmj test/import_external.cmi test/import_external.cmj test/import_side_effect.cmi test/import_side_effect.cmj test/import_side_effect_free.cmi test/import_side_effect_free.cmj test/include_side_effect.cmi test/include_side_effect.cmj test/include_side_effect_free.cmi test/include_side_effect_free.cmj test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj test/infer_type_test.cmi test/infer_type_test.cmj test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj test/inline_const.cmi test/inline_const.cmj test/inline_const_test.cmi test/inline_const_test.cmj test/inline_edge_cases.cmi test/inline_edge_cases.cmj test/inline_map2_test.cmi test/inline_map2_test.cmj test/inline_map_demo.cmi test/inline_map_demo.cmj test/inline_map_test.cmi test/inline_map_test.cmj test/inline_record_test.cmi test/inline_record_test.cmj test/inline_regression_test.cmi test/inline_regression_test.cmj test/inline_string_test.cmi test/inline_string_test.cmj test/inner_call.cmi test/inner_call.cmj test/inner_define.cmi test/inner_define.cmj test/inner_unused.cmi test/inner_unused.cmj test/installation_test.cmi test/installation_test.cmj test/int_map.cmi test/int_map.cmj test/int_overflow_test.cmi test/int_overflow_test.cmj test/int_poly_var.cmi test/int_poly_var.cmj test/int_switch_test.cmi test/int_switch_test.cmj test/internal_unused_test.cmi test/internal_unused_test.cmj test/js_array_test.cmi test/js_array_test.cmj test/js_bool_test.cmi test/js_bool_test.cmj test/js_cast_test.cmi test/js_cast_test.cmj test/js_date_test.cmi test/js_date_test.cmj test/js_dict_test.cmi test/js_dict_test.cmj test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj test/js_float_test.cmi test/js_float_test.cmj test/js_global_test.cmi test/js_global_test.cmj test/js_int_test.cmi test/js_int_test.cmj test/js_json_test.cmi test/js_json_test.cmj test/js_math_test.cmi test/js_math_test.cmj test/js_null_test.cmi test/js_null_test.cmj test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj test/js_nullable_test.cmi test/js_nullable_test.cmj test/js_obj_test.cmi test/js_obj_test.cmj test/js_option_test.cmi test/js_option_test.cmj test/js_re_test.cmi test/js_re_test.cmj test/js_string_test.cmi test/js_string_test.cmj test/js_undefined_test.cmi test/js_undefined_test.cmj test/js_val.cmi test/js_val.cmj test/jsoo_400_test.cmi test/jsoo_400_test.cmj test/jsoo_485_test.cmi test/jsoo_485_test.cmj test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj test/key_word_property.cmi test/key_word_property.cmj test/key_word_property2.cmi test/key_word_property2.cmj test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj test/label_uncurry.cmi test/label_uncurry.cmj test/large_integer_pat.cmi test/large_integer_pat.cmj test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj test/largest_int_flow.cmi test/largest_int_flow.cmj test/lazy_demo.cmi test/lazy_demo.cmj test/lazy_test.cmi test/lazy_test.cmj test/lib_js_test.cmi test/lib_js_test.cmj test/libqueue_test.cmi test/libqueue_test.cmj test/limits_test.cmi test/limits_test.cmj test/list_stack.cmi test/list_stack.cmj test/list_test.cmi test/list_test.cmj test/local_exception_test.cmi test/local_exception_test.cmj test/loop_regression_test.cmi test/loop_regression_test.cmj test/map_find_test.cmi test/map_find_test.cmj test/map_test.cmi test/map_test.cmj test/mario_game.cmi test/mario_game.cmj test/meth_annotation.cmi test/meth_annotation.cmj test/method_name_test.cmi test/method_name_test.cmj test/method_string_name.cmi test/method_string_name.cmj test/minimal_test.cmi test/minimal_test.cmj test/miss_colon_test.cmi test/miss_colon_test.cmj test/mock_mt.cmi test/mock_mt.cmj test/module_alias_test.cmi test/module_alias_test.cmj test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj test/module_as_function.cmi test/module_as_function.cmj test/module_missing_conversion.cmi test/module_missing_conversion.cmj test/module_parameter_test.cmi test/module_parameter_test.cmj test/module_splice_test.cmi test/module_splice_test.cmj test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj test/more_uncurry.cmi test/more_uncurry.cmj test/mpr_6033_test.cmi test/mpr_6033_test.cmj test/mt.cmi test/mt.cmj test/mt_global.cmi test/mt_global.cmj test/mutable_obj_test.cmi test/mutable_obj_test.cmj test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj test/name_mangle_test.cmi test/name_mangle_test.cmj test/nested_include.cmi test/nested_include.cmj test/nested_module_alias.cmi test/nested_module_alias.cmj test/nested_obj_literal.cmi test/nested_obj_literal.cmj test/nested_obj_test.cmi test/nested_obj_test.cmj test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj test/noassert.cmi test/noassert.cmj test/node_assert.cmi test/node_assert.cmj test/node_path_test.cmi test/node_path_test.cmj test/node_test.cmi test/node_test.cmj test/node_test_util.cmi test/node_test_util.cmj test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj test/obj_magic_test.cmi test/obj_magic_test.cmj test/obj_type_test.cmi test/obj_type_test.cmj test/offset.cmi test/offset.cmj test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj test/option_encoding_test.cmi test/option_encoding_test.cmj test/option_repr_test.cmi test/option_repr_test.cmj test/optional_ffi_test.cmi test/optional_ffi_test.cmj test/optional_regression_test.cmi test/optional_regression_test.cmj test/pipe_send_readline.cmi test/pipe_send_readline.cmj test/pipe_syntax.cmi test/pipe_syntax.cmj test/poly_empty_array.cmi test/poly_empty_array.cmj test/poly_variant_test.cmi test/poly_variant_test.cmj test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj test/polymorphism_test.cmi test/polymorphism_test.cmj test/polyvar_convert.cmi test/polyvar_convert.cmj test/polyvar_test.cmi test/polyvar_test.cmj test/ppx_apply_test.cmi test/ppx_apply_test.cmj test/pq_test.cmi test/pq_test.cmj test/pr6726.cmi test/pr6726.cmj test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj test/primitive_reg_test.cmi test/primitive_reg_test.cmj test/print_alpha_test.cmi test/print_alpha_test.cmj test/queue_402.cmi test/queue_402.cmj test/queue_test.cmi test/queue_test.cmj test/raw_output_test.cmi test/raw_output_test.cmj test/raw_pure_test.cmi test/raw_pure_test.cmj test/rbset.cmi test/rbset.cmj test/react.cmi test/react.cmj test/reactDOMRe.cmi test/reactDOMRe.cmj test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj test/reactEvent.cmi test/reactEvent.cmj test/reactTestUtils.cmi test/reactTestUtils.cmj test/reasonReact.cmi test/reasonReact.cmj test/reasonReactCompat.cmi test/reasonReactCompat.cmj test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj test/reasonReactRouter.cmi test/reasonReactRouter.cmj test/rebind_module.cmi test/rebind_module.cmj test/rebind_module_test.cmi test/rebind_module_test.cmj test/rec_array_test.cmi test/rec_array_test.cmj test/rec_fun_test.cmi test/rec_fun_test.cmj test/rec_module_opt.cmi test/rec_module_opt.cmj test/rec_module_test.cmi test/rec_module_test.cmj test/recmodule.cmi test/recmodule.cmj test/record_debug_test.cmi test/record_debug_test.cmj test/record_extension_test.cmi test/record_extension_test.cmj test/record_name_test.cmi test/record_name_test.cmj test/record_regression.cmi test/record_regression.cmj test/record_type_spread.cmi test/record_type_spread.cmj test/record_with_test.cmi test/record_with_test.cmj test/recursive_module.cmi test/recursive_module.cmj test/recursive_module_test.cmi test/recursive_module_test.cmj test/recursive_react_component.cmi test/recursive_react_component.cmj test/recursive_records_test.cmi test/recursive_records_test.cmj test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj test/regression_print.cmi test/regression_print.cmj test/relative_path.cmi test/relative_path.cmj test/res_debug.cmi test/res_debug.cmj test/return_check.cmi test/return_check.cmj test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj test/set_annotation.cmi test/set_annotation.cmj test/set_gen.cmi test/set_gen.cmj test/side_effect.cmi test/side_effect.cmj test/side_effect2.cmi test/side_effect2.cmj test/side_effect_free.cmi test/side_effect_free.cmj test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj test/single_module_alias.cmi test/single_module_alias.cmj test/singular_unit_test.cmi test/singular_unit_test.cmj test/small_inline_test.cmi test/small_inline_test.cmj test/splice_test.cmi test/splice_test.cmj test/stack_comp_test.cmi test/stack_comp_test.cmj test/stack_test.cmi test/stack_test.cmj test/string_bound_get_test.cmi test/string_bound_get_test.cmj test/string_constant_compare.cmi test/string_constant_compare.cmj test/string_set.cmi test/string_set.cmj test/string_set_test.cmi test/string_set_test.cmj test/string_unicode_test.cmi test/string_unicode_test.cmj test/stringmatch_test.cmi test/stringmatch_test.cmj test/submodule.cmi test/submodule.cmj test/submodule_call.cmi test/submodule_call.cmj test/switch_case_test.cmi test/switch_case_test.cmj test/switch_string.cmi test/switch_string.cmj test/tagged_template_test.cmi test/tagged_template_test.cmj test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj test/template.cmi test/template.cmj test/test2.cmi test/test2.cmj test/test_alias.cmi test/test_alias.cmj test/test_ari.cmi test/test_ari.cmj test/test_array.cmi test/test_array.cmj test/test_array_append.cmi test/test_array_append.cmj test/test_bool_equal.cmi test/test_bool_equal.cmj test/test_bs_this.cmi test/test_bs_this.cmj test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj test/test_case_set.cmi test/test_case_set.cmj test/test_char.cmi test/test_char.cmj test/test_closure.cmi test/test_closure.cmj test/test_common.cmi test/test_common.cmj test/test_const_elim.cmi test/test_const_elim.cmj test/test_const_propogate.cmi test/test_const_propogate.cmj test/test_cpp.cmi test/test_cpp.cmj test/test_cps.cmi test/test_cps.cmj test/test_demo.cmi test/test_demo.cmj test/test_dup_param.cmi test/test_dup_param.cmj test/test_eq.cmi test/test_eq.cmj test/test_exception.cmi test/test_exception.cmj test/test_exception_escape.cmi test/test_exception_escape.cmj test/test_export2.cmi test/test_export2.cmj test/test_external.cmi test/test_external.cmj test/test_external_unit.cmi test/test_external_unit.cmj test/test_ffi.cmi test/test_ffi.cmj test/test_fib.cmi test/test_fib.cmj test/test_for_loop.cmi test/test_for_loop.cmj test/test_for_map.cmi test/test_for_map.cmj test/test_for_map2.cmi test/test_for_map2.cmj test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj test/test_generative_module.cmi test/test_generative_module.cmj test/test_global_print.cmi test/test_global_print.cmj test/test_google_closure.cmi test/test_google_closure.cmj test/test_include.cmi test/test_include.cmj test/test_incomplete.cmi test/test_incomplete.cmj test/test_incr_ref.cmi test/test_incr_ref.cmj test/test_int_map_find.cmi test/test_int_map_find.cmj test/test_is_js.cmi test/test_is_js.cmj test/test_js_ffi.cmi test/test_js_ffi.cmj test/test_let.cmi test/test_let.cmj test/test_list.cmi test/test_list.cmj test/test_literal.cmi test/test_literal.cmj test/test_literals.cmi test/test_literals.cmj test/test_match_exception.cmi test/test_match_exception.cmj test/test_mutliple.cmi test/test_mutliple.cmj test/test_nested_let.cmi test/test_nested_let.cmj test/test_nested_print.cmi test/test_nested_print.cmj test/test_non_export.cmi test/test_non_export.cmj test/test_nullary.cmi test/test_nullary.cmj test/test_obj.cmi test/test_obj.cmj test/test_order.cmi test/test_order.cmj test/test_order_tailcall.cmi test/test_order_tailcall.cmj test/test_other_exn.cmi test/test_other_exn.cmj test/test_per.cmi test/test_per.cmj test/test_pervasive.cmi test/test_pervasive.cmj test/test_pervasives2.cmi test/test_pervasives2.cmj test/test_pervasives3.cmi test/test_pervasives3.cmj test/test_primitive.cmi test/test_primitive.cmj test/test_ramification.cmi test/test_ramification.cmj test/test_react.cmi test/test_react.cmj test/test_react_case.cmi test/test_react_case.cmj test/test_regex.cmi test/test_regex.cmj test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj test/test_scope.cmi test/test_scope.cmj test/test_seq.cmi test/test_seq.cmj test/test_set.cmi test/test_set.cmj test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj test/test_simple_include.cmi test/test_simple_include.cmj test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj test/test_simple_ref.cmi test/test_simple_ref.cmj test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj test/test_small.cmi test/test_small.cmj test/test_stack.cmi test/test_stack.cmj test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj test/test_string.cmi test/test_string.cmj test/test_string_case.cmi test/test_string_case.cmj test/test_string_const.cmi test/test_string_const.cmj test/test_string_map.cmi test/test_string_map.cmj test/test_string_switch.cmi test/test_string_switch.cmj test/test_switch.cmi test/test_switch.cmj test/test_trywith.cmi test/test_trywith.cmj test/test_tuple.cmi test/test_tuple.cmj test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj test/test_type_based_arity.cmi test/test_type_based_arity.cmj test/test_u.cmi test/test_u.cmj test/test_unknown.cmi test/test_unknown.cmj test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj test/test_unsafe_obj_ffi.cmi test/test_unsafe_obj_ffi.cmj test/test_unsafe_obj_ffi_ppx.cmi test/test_unsafe_obj_ffi_ppx.cmj test/test_while_closure.cmi test/test_while_closure.cmj test/test_while_side_effect.cmi test/test_while_side_effect.cmj test/test_zero_nullable.cmi test/test_zero_nullable.cmj test/then_mangle_test.cmi test/then_mangle_test.cmj test/ticker.cmi test/ticker.cmj test/to_string_test.cmi test/to_string_test.cmj test/topsort_test.cmi test/topsort_test.cmj test/tramp_fib.cmi test/tramp_fib.cmj test/tuple_alloc.cmi test/tuple_alloc.cmj test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj test/type_disambiguate.cmi test/type_disambiguate.cmj test/typeof_test.cmi test/typeof_test.cmj test/unboxed_attribute.cmi test/unboxed_attribute.cmj test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj test/unboxed_crash.cmi test/unboxed_crash.cmj test/unboxed_use_case.cmi test/unboxed_use_case.cmj test/uncurried_cast.cmi test/uncurried_cast.cmj test/uncurried_default.args.cmi test/uncurried_default.args.cmj test/uncurried_pipe.cmi test/uncurried_pipe.cmj test/uncurry_external_test.cmi test/uncurry_external_test.cmj test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj test/uncurry_test.cmi test/uncurry_test.cmj test/undef_regression_test.cmi test/undef_regression_test.cmj test/unit_undefined_test.cmi test/unit_undefined_test.cmj test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj test/update_record_test.cmi test/update_record_test.cmj test/variant.cmi test/variant.cmj test/variantsMatching.cmi test/variantsMatching.cmj test/webpack_config.cmi test/webpack_config.cmj +o test : phony test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj test/Coercion.cmi test/Coercion.cmj test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj test/DictInference.cmi test/DictInference.cmj test/DictTests.cmi test/DictTests.cmj test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj test/DotDotDot.cmi test/DotDotDot.cmj test/EmptyRecord.cmi test/EmptyRecord.cmj test/ExternalArity.cmi test/ExternalArity.cmj test/FFI.cmi test/FFI.cmj test/Import.cmi test/Import.cmj test/ImportAttributes.cmi test/ImportAttributes.cmj test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj test/RecordCoercion.cmi test/RecordCoercion.cmj test/RecordOrObject.cmi test/RecordOrObject.cmj test/SafePromises.cmi test/SafePromises.cmj test/UncurriedAlways.cmi test/UncurriedAlways.cmj test/UncurriedExternals.cmi test/UncurriedExternals.cmj test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj test/UntaggedVariants.cmi test/UntaggedVariants.cmj test/VariantCoercion.cmi test/VariantCoercion.cmj test/VariantSpreads.cmi test/VariantSpreads.cmj test/a.cmi test/a.cmj test/a_recursive_type.cmi test/a_recursive_type.cmj test/a_scope_bug.cmi test/a_scope_bug.cmj test/abstract_type.cmi test/abstract_type.cmj test/adt_optimize_test.cmi test/adt_optimize_test.cmj test/alias_default_value_test.cmi test/alias_default_value_test.cmj test/alias_test.cmi test/alias_test.cmj test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj test/ari_regress_test.cmi test/ari_regress_test.cmj test/arith_syntax.cmi test/arith_syntax.cmj test/arity.cmi test/arity.cmj test/arity_deopt.cmi test/arity_deopt.cmj test/arity_infer.cmi test/arity_infer.cmj test/array_data_util.cmi test/array_data_util.cmj test/array_safe_get.cmi test/array_safe_get.cmj test/array_subtle_test.cmi test/array_subtle_test.cmj test/as_inline_record_test.cmi test/as_inline_record_test.cmj test/ast_abstract_test.cmi test/ast_abstract_test.cmj test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj test/async_await.cmi test/async_await.cmj test/async_inline.cmi test/async_inline.cmj test/async_inside_loop.cmi test/async_inside_loop.cmj test/attr_test.cmi test/attr_test.cmj test/b.cmi test/b.cmj test/bal_set_mini.cmi test/bal_set_mini.cmj test/bang_primitive.cmi test/bang_primitive.cmj test/bb.cmi test/bb.cmj test/bdd.cmi test/bdd.cmj test/belt_float_ntest.cmi test/belt_float_ntest.cmj test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj test/belt_int_ntest.cmi test/belt_int_ntest.cmj test/belt_internal_test.cmi test/belt_internal_test.cmj test/belt_list_ntest.cmi test/belt_list_ntest.cmj test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj test/bench.cmi test/bench.cmj test/big_enum.cmi test/big_enum.cmj test/big_polyvar_test.cmi test/big_polyvar_test.cmj test/bigint_test.cmi test/bigint_test.cmj test/block_alias_test.cmi test/block_alias_test.cmj test/boolean_test.cmi test/boolean_test.cmj test/bs_abstract_test.cmi test/bs_abstract_test.cmj test/bs_array_test.cmi test/bs_array_test.cmj test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj test/bs_ignore_test.cmi test/bs_ignore_test.cmj test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj test/bs_map_test.cmi test/bs_map_test.cmj test/bs_min_max_test.cmi test/bs_min_max_test.cmj test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj test/bs_qualified.cmi test/bs_qualified.cmj test/bs_queue_test.cmi test/bs_queue_test.cmj test/bs_rest_test.cmi test/bs_rest_test.cmj test/bs_set_int_test.cmi test/bs_set_int_test.cmj test/bs_splice_partial.cmi test/bs_splice_partial.cmj test/bs_stack_test.cmi test/bs_stack_test.cmj test/bs_string_test.cmi test/bs_string_test.cmj test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj test/caml_compare_test.cmi test/caml_compare_test.cmj test/chain_code_test.cmi test/chain_code_test.cmj test/chn_test.cmi test/chn_test.cmj test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj test/compare_test.cmi test/compare_test.cmj test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj test/complex_while_loop.cmi test/complex_while_loop.cmj test/condition_compilation_test.cmi test/condition_compilation_test.cmj test/config1_test.cmi test/config1_test.cmj test/console_log_test.cmi test/console_log_test.cmj test/const_block_test.cmi test/const_block_test.cmj test/const_defs.cmi test/const_defs.cmj test/const_defs_test.cmi test/const_defs_test.cmj test/const_test.cmi test/const_test.cmj test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj test/cps_test.cmi test/cps_test.cmj test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj test/custom_error_test.cmi test/custom_error_test.cmj test/debug_keep_test.cmi test/debug_keep_test.cmj test/debug_mode_value.cmi test/debug_mode_value.cmj test/debug_tmp.cmi test/debug_tmp.cmj test/debugger_test.cmi test/debugger_test.cmj test/default_export_test.cmi test/default_export_test.cmj test/defunctor_make_test.cmi test/defunctor_make_test.cmj test/demo_int_map.cmi test/demo_int_map.cmj test/demo_page.cmi test/demo_page.cmj test/demo_pipe.cmi test/demo_pipe.cmj test/derive_projector_test.cmi test/derive_projector_test.cmj test/directives.cmi test/directives.cmj test/div_by_zero_test.cmi test/div_by_zero_test.cmj test/dollar_escape_test.cmi test/dollar_escape_test.cmj test/earger_curry_test.cmi test/earger_curry_test.cmj test/effect.cmi test/effect.cmj test/epsilon_test.cmi test/epsilon_test.cmj test/equal_box_test.cmi test/equal_box_test.cmj test/equal_exception_test.cmi test/equal_exception_test.cmj test/equal_test.cmi test/equal_test.cmj test/es6_export.cmi test/es6_export.cmj test/es6_import.cmi test/es6_import.cmj test/es6_module_test.cmi test/es6_module_test.cmj test/escape_esmodule.cmi test/escape_esmodule.cmj test/esmodule_ref.cmi test/esmodule_ref.cmj test/event_ffi.cmi test/event_ffi.cmj test/exception_alias.cmi test/exception_alias.cmj test/exception_raise_test.cmi test/exception_raise_test.cmj test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj test/exception_value_test.cmi test/exception_value_test.cmj test/exotic_labels_test.cmi test/exotic_labels_test.cmj test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj test/export_keyword.cmi test/export_keyword.cmj test/ext_array_test.cmi test/ext_array_test.cmj test/ext_pervasives_test.cmi test/ext_pervasives_test.cmj test/extensible_variant_test.cmi test/extensible_variant_test.cmj test/external_ppx.cmi test/external_ppx.cmj test/external_ppx2.cmi test/external_ppx2.cmj test/ffi_arity_test.cmi test/ffi_arity_test.cmj test/ffi_array_test.cmi test/ffi_array_test.cmj test/ffi_js_test.cmi test/ffi_js_test.cmj test/ffi_splice_test.cmi test/ffi_splice_test.cmj test/ffi_test.cmi test/ffi_test.cmj test/fib.cmi test/fib.cmj test/flattern_order_test.cmi test/flattern_order_test.cmj test/flexible_array_test.cmi test/flexible_array_test.cmj test/float_array.cmi test/float_array.cmj test/float_record.cmi test/float_record.cmj test/float_test.cmi test/float_test.cmj test/for_loop_test.cmi test/for_loop_test.cmj test/for_side_effect_test.cmi test/for_side_effect_test.cmj test/format_regression.cmi test/format_regression.cmj test/fun_pattern_match.cmi test/fun_pattern_match.cmj test/function_directives.cmi test/function_directives.cmj test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj test/functor_app_test.cmi test/functor_app_test.cmj test/functor_def.cmi test/functor_def.cmj test/functor_ffi.cmi test/functor_ffi.cmj test/functor_inst.cmi test/functor_inst.cmj test/functors.cmi test/functors.cmj test/gbk.cmi test/gbk.cmj test/gentTypeReTest.cmi test/gentTypeReTest.cmj test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj test/global_mangles.cmi test/global_mangles.cmj test/global_module_alias_test.cmi test/global_module_alias_test.cmj test/google_closure_test.cmi test/google_closure_test.cmj test/gpr496_test.cmi test/gpr496_test.cmj test/gpr_1072.cmi test/gpr_1072.cmj test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj test/gpr_1150.cmi test/gpr_1150.cmj test/gpr_1170.cmi test/gpr_1170.cmj test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj test/gpr_1245_test.cmi test/gpr_1245_test.cmj test/gpr_1268.cmi test/gpr_1268.cmj test/gpr_1409_test.cmi test/gpr_1409_test.cmj test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj test/gpr_1438.cmi test/gpr_1438.cmj test/gpr_1481.cmi test/gpr_1481.cmj test/gpr_1484.cmi test/gpr_1484.cmj test/gpr_1539_test.cmi test/gpr_1539_test.cmj test/gpr_1658_test.cmi test/gpr_1658_test.cmj test/gpr_1667_test.cmi test/gpr_1667_test.cmj test/gpr_1692_test.cmi test/gpr_1692_test.cmj test/gpr_1698_test.cmi test/gpr_1698_test.cmj test/gpr_1701_test.cmi test/gpr_1701_test.cmj test/gpr_1716_test.cmi test/gpr_1716_test.cmj test/gpr_1717_test.cmi test/gpr_1717_test.cmj test/gpr_1728_test.cmi test/gpr_1728_test.cmj test/gpr_1749_test.cmi test/gpr_1749_test.cmj test/gpr_1759_test.cmi test/gpr_1759_test.cmj test/gpr_1760_test.cmi test/gpr_1760_test.cmj test/gpr_1762_test.cmi test/gpr_1762_test.cmj test/gpr_1817_test.cmi test/gpr_1817_test.cmj test/gpr_1822_test.cmi test/gpr_1822_test.cmj test/gpr_1891_test.cmi test/gpr_1891_test.cmj test/gpr_1943_test.cmi test/gpr_1943_test.cmj test/gpr_1946_test.cmi test/gpr_1946_test.cmj test/gpr_2316_test.cmi test/gpr_2316_test.cmj test/gpr_2352_test.cmi test/gpr_2352_test.cmj test/gpr_2413_test.cmi test/gpr_2413_test.cmj test/gpr_2474.cmi test/gpr_2474.cmj test/gpr_2487.cmi test/gpr_2487.cmj test/gpr_2503_test.cmi test/gpr_2503_test.cmj test/gpr_2608_test.cmi test/gpr_2608_test.cmj test/gpr_2614_test.cmi test/gpr_2614_test.cmj test/gpr_2633_test.cmi test/gpr_2633_test.cmj test/gpr_2642_test.cmi test/gpr_2642_test.cmj test/gpr_2682_test.cmi test/gpr_2682_test.cmj test/gpr_2700_test.cmi test/gpr_2700_test.cmj test/gpr_2731_test.cmi test/gpr_2731_test.cmj test/gpr_2789_test.cmi test/gpr_2789_test.cmj test/gpr_2931_test.cmi test/gpr_2931_test.cmj test/gpr_3142_test.cmi test/gpr_3142_test.cmj test/gpr_3154_test.cmi test/gpr_3154_test.cmj test/gpr_3209_test.cmi test/gpr_3209_test.cmj test/gpr_3492_test.cmi test/gpr_3492_test.cmj test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj test/gpr_3519_test.cmi test/gpr_3519_test.cmj test/gpr_3536_test.cmi test/gpr_3536_test.cmj test/gpr_3546_test.cmi test/gpr_3546_test.cmj test/gpr_3548_test.cmi test/gpr_3548_test.cmj test/gpr_3549_test.cmi test/gpr_3549_test.cmj test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj test/gpr_3566_test.cmi test/gpr_3566_test.cmj test/gpr_3595_test.cmi test/gpr_3595_test.cmj test/gpr_3609_test.cmi test/gpr_3609_test.cmj test/gpr_3697_test.cmi test/gpr_3697_test.cmj test/gpr_373_test.cmi test/gpr_373_test.cmj test/gpr_3770_test.cmi test/gpr_3770_test.cmj test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj test/gpr_3852_alias_reify.cmi test/gpr_3852_alias_reify.cmj test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj test/gpr_3865.cmi test/gpr_3865.cmj test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj test/gpr_3875_test.cmi test/gpr_3875_test.cmj test/gpr_3877_test.cmi test/gpr_3877_test.cmj test/gpr_3895_test.cmi test/gpr_3895_test.cmj test/gpr_3897_test.cmi test/gpr_3897_test.cmj test/gpr_3931_test.cmi test/gpr_3931_test.cmj test/gpr_3980_test.cmi test/gpr_3980_test.cmj test/gpr_4025_test.cmi test/gpr_4025_test.cmj test/gpr_4069_test.cmi test/gpr_4069_test.cmj test/gpr_4265_test.cmi test/gpr_4265_test.cmj test/gpr_4274_test.cmi test/gpr_4274_test.cmj test/gpr_4280_test.cmi test/gpr_4280_test.cmj test/gpr_4407_test.cmi test/gpr_4407_test.cmj test/gpr_441.cmi test/gpr_441.cmj test/gpr_4442_test.cmi test/gpr_4442_test.cmj test/gpr_4491_test.cmi test/gpr_4491_test.cmj test/gpr_4494_test.cmi test/gpr_4494_test.cmj test/gpr_4519_test.cmi test/gpr_4519_test.cmj test/gpr_459_test.cmi test/gpr_459_test.cmj test/gpr_4632.cmi test/gpr_4632.cmj test/gpr_4639_test.cmi test/gpr_4639_test.cmj test/gpr_4900_test.cmi test/gpr_4900_test.cmj test/gpr_4924_test.cmi test/gpr_4924_test.cmj test/gpr_4931.cmi test/gpr_4931.cmj test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj test/gpr_5071_test.cmi test/gpr_5071_test.cmj test/gpr_5169_test.cmi test/gpr_5169_test.cmj test/gpr_5218_test.cmi test/gpr_5218_test.cmj test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj test/gpr_5557.cmi test/gpr_5557.cmj test/gpr_5753.cmi test/gpr_5753.cmj test/gpr_658.cmi test/gpr_658.cmj test/gpr_7012_test.cmi test/gpr_7012_test.cmj test/gpr_858_test.cmi test/gpr_858_test.cmj test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj test/gpr_904_test.cmi test/gpr_904_test.cmj test/gpr_974_test.cmi test/gpr_974_test.cmj test/gpr_977_test.cmi test/gpr_977_test.cmj test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj test/gray_code_test.cmi test/gray_code_test.cmj test/guide_for_ext.cmi test/guide_for_ext.cmj test/hash_collision_test.cmi test/hash_collision_test.cmj test/hash_sugar_desugar.cmi test/hash_sugar_desugar.cmj test/hash_test.cmi test/hash_test.cmj test/hello.foo.cmi test/hello.foo.cmj test/hello_res.cmi test/hello_res.cmj test/ignore_test.cmi test/ignore_test.cmj test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj test/import2.cmi test/import2.cmj test/import_external.cmi test/import_external.cmj test/import_side_effect.cmi test/import_side_effect.cmj test/import_side_effect_free.cmi test/import_side_effect_free.cmj test/include_side_effect.cmi test/include_side_effect.cmj test/include_side_effect_free.cmi test/include_side_effect_free.cmj test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj test/infer_type_test.cmi test/infer_type_test.cmj test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj test/inline_const.cmi test/inline_const.cmj test/inline_const_test.cmi test/inline_const_test.cmj test/inline_edge_cases.cmi test/inline_edge_cases.cmj test/inline_map2_test.cmi test/inline_map2_test.cmj test/inline_map_demo.cmi test/inline_map_demo.cmj test/inline_map_test.cmi test/inline_map_test.cmj test/inline_record_test.cmi test/inline_record_test.cmj test/inline_regression_test.cmi test/inline_regression_test.cmj test/inline_string_test.cmi test/inline_string_test.cmj test/inner_call.cmi test/inner_call.cmj test/inner_define.cmi test/inner_define.cmj test/inner_unused.cmi test/inner_unused.cmj test/installation_test.cmi test/installation_test.cmj test/int_map.cmi test/int_map.cmj test/int_overflow_test.cmi test/int_overflow_test.cmj test/int_poly_var.cmi test/int_poly_var.cmj test/int_switch_test.cmi test/int_switch_test.cmj test/internal_unused_test.cmi test/internal_unused_test.cmj test/js_array_test.cmi test/js_array_test.cmj test/js_bool_test.cmi test/js_bool_test.cmj test/js_cast_test.cmi test/js_cast_test.cmj test/js_date_test.cmi test/js_date_test.cmj test/js_dict_test.cmi test/js_dict_test.cmj test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj test/js_float_test.cmi test/js_float_test.cmj test/js_global_test.cmi test/js_global_test.cmj test/js_int_test.cmi test/js_int_test.cmj test/js_json_test.cmi test/js_json_test.cmj test/js_math_test.cmi test/js_math_test.cmj test/js_null_test.cmi test/js_null_test.cmj test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj test/js_nullable_test.cmi test/js_nullable_test.cmj test/js_obj_test.cmi test/js_obj_test.cmj test/js_option_test.cmi test/js_option_test.cmj test/js_re_test.cmi test/js_re_test.cmj test/js_string_test.cmi test/js_string_test.cmj test/js_undefined_test.cmi test/js_undefined_test.cmj test/js_val.cmi test/js_val.cmj test/jsoo_400_test.cmi test/jsoo_400_test.cmj test/jsoo_485_test.cmi test/jsoo_485_test.cmj test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj test/key_word_property.cmi test/key_word_property.cmj test/key_word_property2.cmi test/key_word_property2.cmj test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj test/label_uncurry.cmi test/label_uncurry.cmj test/large_integer_pat.cmi test/large_integer_pat.cmj test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj test/largest_int_flow.cmi test/largest_int_flow.cmj test/lazy_demo.cmi test/lazy_demo.cmj test/lazy_test.cmi test/lazy_test.cmj test/lib_js_test.cmi test/lib_js_test.cmj test/limits_test.cmi test/limits_test.cmj test/list_test.cmi test/list_test.cmj test/local_exception_test.cmi test/local_exception_test.cmj test/loop_regression_test.cmi test/loop_regression_test.cmj test/map_find_test.cmi test/map_find_test.cmj test/mario_game.cmi test/mario_game.cmj test/meth_annotation.cmi test/meth_annotation.cmj test/method_name_test.cmi test/method_name_test.cmj test/method_string_name.cmi test/method_string_name.cmj test/minimal_test.cmi test/minimal_test.cmj test/miss_colon_test.cmi test/miss_colon_test.cmj test/mock_mt.cmi test/mock_mt.cmj test/module_alias_test.cmi test/module_alias_test.cmj test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj test/module_as_function.cmi test/module_as_function.cmj test/module_missing_conversion.cmi test/module_missing_conversion.cmj test/module_parameter_test.cmi test/module_parameter_test.cmj test/module_splice_test.cmi test/module_splice_test.cmj test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj test/more_uncurry.cmi test/more_uncurry.cmj test/mpr_6033_test.cmi test/mpr_6033_test.cmj test/mt.cmi test/mt.cmj test/mt_global.cmi test/mt_global.cmj test/mutable_obj_test.cmi test/mutable_obj_test.cmj test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj test/name_mangle_test.cmi test/name_mangle_test.cmj test/nested_include.cmi test/nested_include.cmj test/nested_module_alias.cmi test/nested_module_alias.cmj test/nested_obj_literal.cmi test/nested_obj_literal.cmj test/nested_obj_test.cmi test/nested_obj_test.cmj test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj test/noassert.cmi test/noassert.cmj test/node_assert.cmi test/node_assert.cmj test/node_path_test.cmi test/node_path_test.cmj test/node_test.cmi test/node_test.cmj test/node_test_util.cmi test/node_test_util.cmj test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj test/obj_magic_test.cmi test/obj_magic_test.cmj test/obj_type_test.cmi test/obj_type_test.cmj test/offset.cmi test/offset.cmj test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj test/option_encoding_test.cmi test/option_encoding_test.cmj test/option_repr_test.cmi test/option_repr_test.cmj test/optional_ffi_test.cmi test/optional_ffi_test.cmj test/optional_regression_test.cmi test/optional_regression_test.cmj test/pipe_send_readline.cmi test/pipe_send_readline.cmj test/pipe_syntax.cmi test/pipe_syntax.cmj test/poly_empty_array.cmi test/poly_empty_array.cmj test/poly_variant_test.cmi test/poly_variant_test.cmj test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj test/polymorphism_test.cmi test/polymorphism_test.cmj test/polyvar_convert.cmi test/polyvar_convert.cmj test/polyvar_test.cmi test/polyvar_test.cmj test/ppx_apply_test.cmi test/ppx_apply_test.cmj test/pq_test.cmi test/pq_test.cmj test/pr6726.cmi test/pr6726.cmj test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj test/primitive_reg_test.cmi test/primitive_reg_test.cmj test/print_alpha_test.cmi test/print_alpha_test.cmj test/queue_402.cmi test/queue_402.cmj test/raw_output_test.cmi test/raw_output_test.cmj test/raw_pure_test.cmi test/raw_pure_test.cmj test/rbset.cmi test/rbset.cmj test/react.cmi test/react.cmj test/reactDOMRe.cmi test/reactDOMRe.cmj test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj test/reactEvent.cmi test/reactEvent.cmj test/reactTestUtils.cmi test/reactTestUtils.cmj test/reasonReact.cmi test/reasonReact.cmj test/reasonReactCompat.cmi test/reasonReactCompat.cmj test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj test/reasonReactRouter.cmi test/reasonReactRouter.cmj test/rebind_module.cmi test/rebind_module.cmj test/rebind_module_test.cmi test/rebind_module_test.cmj test/rec_array_test.cmi test/rec_array_test.cmj test/rec_fun_test.cmi test/rec_fun_test.cmj test/rec_module_opt.cmi test/rec_module_opt.cmj test/rec_module_test.cmi test/rec_module_test.cmj test/recmodule.cmi test/recmodule.cmj test/record_debug_test.cmi test/record_debug_test.cmj test/record_extension_test.cmi test/record_extension_test.cmj test/record_name_test.cmi test/record_name_test.cmj test/record_regression.cmi test/record_regression.cmj test/record_type_spread.cmi test/record_type_spread.cmj test/record_with_test.cmi test/record_with_test.cmj test/recursive_module.cmi test/recursive_module.cmj test/recursive_module_test.cmi test/recursive_module_test.cmj test/recursive_react_component.cmi test/recursive_react_component.cmj test/recursive_records_test.cmi test/recursive_records_test.cmj test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj test/regression_print.cmi test/regression_print.cmj test/relative_path.cmi test/relative_path.cmj test/res_debug.cmi test/res_debug.cmj test/return_check.cmi test/return_check.cmj test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj test/set_annotation.cmi test/set_annotation.cmj test/set_gen.cmi test/set_gen.cmj test/side_effect.cmi test/side_effect.cmj test/side_effect2.cmi test/side_effect2.cmj test/side_effect_free.cmi test/side_effect_free.cmj test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj test/singular_unit_test.cmi test/singular_unit_test.cmj test/small_inline_test.cmi test/small_inline_test.cmj test/splice_test.cmi test/splice_test.cmj test/string_bound_get_test.cmi test/string_bound_get_test.cmj test/string_constant_compare.cmi test/string_constant_compare.cmj test/string_set.cmi test/string_set.cmj test/string_set_test.cmi test/string_set_test.cmj test/string_unicode_test.cmi test/string_unicode_test.cmj test/stringmatch_test.cmi test/stringmatch_test.cmj test/submodule.cmi test/submodule.cmj test/submodule_call.cmi test/submodule_call.cmj test/switch_case_test.cmi test/switch_case_test.cmj test/switch_string.cmi test/switch_string.cmj test/tagged_template_test.cmi test/tagged_template_test.cmj test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj test/template.cmi test/template.cmj test/test2.cmi test/test2.cmj test/test_ari.cmi test/test_ari.cmj test/test_array.cmi test/test_array.cmj test/test_array_append.cmi test/test_array_append.cmj test/test_bool_equal.cmi test/test_bool_equal.cmj test/test_bs_this.cmi test/test_bs_this.cmj test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj test/test_case_set.cmi test/test_case_set.cmj test/test_char.cmi test/test_char.cmj test/test_closure.cmi test/test_closure.cmj test/test_common.cmi test/test_common.cmj test/test_const_elim.cmi test/test_const_elim.cmj test/test_const_propogate.cmi test/test_const_propogate.cmj test/test_cpp.cmi test/test_cpp.cmj test/test_cps.cmi test/test_cps.cmj test/test_demo.cmi test/test_demo.cmj test/test_dup_param.cmi test/test_dup_param.cmj test/test_eq.cmi test/test_eq.cmj test/test_exception.cmi test/test_exception.cmj test/test_exception_escape.cmi test/test_exception_escape.cmj test/test_export2.cmi test/test_export2.cmj test/test_external.cmi test/test_external.cmj test/test_external_unit.cmi test/test_external_unit.cmj test/test_ffi.cmi test/test_ffi.cmj test/test_fib.cmi test/test_fib.cmj test/test_for_loop.cmi test/test_for_loop.cmj test/test_for_map.cmi test/test_for_map.cmj test/test_for_map2.cmi test/test_for_map2.cmj test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj test/test_generative_module.cmi test/test_generative_module.cmj test/test_google_closure.cmi test/test_google_closure.cmj test/test_include.cmi test/test_include.cmj test/test_incomplete.cmi test/test_incomplete.cmj test/test_incr_ref.cmi test/test_incr_ref.cmj test/test_int_map_find.cmi test/test_int_map_find.cmj test/test_is_js.cmi test/test_is_js.cmj test/test_js_ffi.cmi test/test_js_ffi.cmj test/test_let.cmi test/test_let.cmj test/test_list.cmi test/test_list.cmj test/test_literal.cmi test/test_literal.cmj test/test_literals.cmi test/test_literals.cmj test/test_match_exception.cmi test/test_match_exception.cmj test/test_nested_let.cmi test/test_nested_let.cmj test/test_nested_print.cmi test/test_nested_print.cmj test/test_non_export.cmi test/test_non_export.cmj test/test_nullary.cmi test/test_nullary.cmj test/test_obj.cmi test/test_obj.cmj test/test_order.cmi test/test_order.cmj test/test_order_tailcall.cmi test/test_order_tailcall.cmj test/test_other_exn.cmi test/test_other_exn.cmj test/test_per.cmi test/test_per.cmj test/test_pervasive.cmi test/test_pervasive.cmj test/test_pervasives3.cmi test/test_pervasives3.cmj test/test_primitive.cmi test/test_primitive.cmj test/test_ramification.cmi test/test_ramification.cmj test/test_react.cmi test/test_react.cmj test/test_react_case.cmi test/test_react_case.cmj test/test_regex.cmi test/test_regex.cmj test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj test/test_scope.cmi test/test_scope.cmj test/test_seq.cmi test/test_seq.cmj test/test_set.cmi test/test_set.cmj test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj test/test_simple_include.cmi test/test_simple_include.cmj test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj test/test_simple_ref.cmi test/test_simple_ref.cmj test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj test/test_small.cmi test/test_small.cmj test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj test/test_string.cmi test/test_string.cmj test/test_string_case.cmi test/test_string_case.cmj test/test_string_const.cmi test/test_string_const.cmj test/test_string_map.cmi test/test_string_map.cmj test/test_string_switch.cmi test/test_string_switch.cmj test/test_switch.cmi test/test_switch.cmj test/test_trywith.cmi test/test_trywith.cmj test/test_tuple.cmi test/test_tuple.cmj test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj test/test_type_based_arity.cmi test/test_type_based_arity.cmj test/test_u.cmi test/test_u.cmj test/test_unknown.cmi test/test_unknown.cmj test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj test/test_unsafe_obj_ffi.cmi test/test_unsafe_obj_ffi.cmj test/test_unsafe_obj_ffi_ppx.cmi test/test_unsafe_obj_ffi_ppx.cmj test/test_while_closure.cmi test/test_while_closure.cmj test/test_while_side_effect.cmi test/test_while_side_effect.cmj test/test_zero_nullable.cmi test/test_zero_nullable.cmj test/then_mangle_test.cmi test/then_mangle_test.cmj test/ticker.cmi test/ticker.cmj test/to_string_test.cmi test/to_string_test.cmj test/topsort_test.cmi test/topsort_test.cmj test/tramp_fib.cmi test/tramp_fib.cmj test/tuple_alloc.cmi test/tuple_alloc.cmj test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj test/type_disambiguate.cmi test/type_disambiguate.cmj test/typeof_test.cmi test/typeof_test.cmj test/unboxed_attribute.cmi test/unboxed_attribute.cmj test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj test/unboxed_crash.cmi test/unboxed_crash.cmj test/unboxed_use_case.cmi test/unboxed_use_case.cmj test/uncurried_cast.cmi test/uncurried_cast.cmj test/uncurried_default.args.cmi test/uncurried_default.args.cmj test/uncurried_pipe.cmi test/uncurried_pipe.cmj test/uncurry_external_test.cmi test/uncurry_external_test.cmj test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj test/uncurry_test.cmi test/uncurry_test.cmj test/undef_regression_test.cmi test/undef_regression_test.cmj test/unit_undefined_test.cmi test/unit_undefined_test.cmj test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj test/update_record_test.cmi test/update_record_test.cmj test/variant.cmi test/variant.cmj test/variantsMatching.cmi test/variantsMatching.cmj test/webpack_config.cmi test/webpack_config.cmj diff --git a/jscomp/test/coercion_module_alias_test.js b/jscomp/test/coercion_module_alias_test.js index 5d8e7c4612..8c625a385d 100644 --- a/jscomp/test/coercion_module_alias_test.js +++ b/jscomp/test/coercion_module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Char = require("../../lib/js/char.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function l(prim) { console.log(prim); @@ -24,10 +24,10 @@ let prim$2 = Char.chr(66); console.log(prim$2); -let f = List.length; +let f = Belt_List.length; function g(x) { - return List.length(List.map(prim => prim + 1 | 0, x)); + return Belt_List.length(Belt_List.map(x, prim => prim + 1 | 0)); } function F(X) { diff --git a/jscomp/test/coercion_module_alias_test.res b/jscomp/test/coercion_module_alias_test.res index e89afae008..70cfb77cfb 100644 --- a/jscomp/test/coercion_module_alias_test.res +++ b/jscomp/test/coercion_module_alias_test.res @@ -1,3 +1,5 @@ +open Belt + let l = Js.log module C = Char @@ -22,7 +24,7 @@ let f = x => { } let g = x => { module L = List - L.length(L.map(succ, x)) + L.length(L.map(x, succ)) } module F = (X: {}) => Char diff --git a/jscomp/test/complex_test.js b/jscomp/test/complex_test.js deleted file mode 100644 index e822054260..0000000000 --- a/jscomp/test/complex_test.js +++ /dev/null @@ -1,27 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Complex = require("../../lib/js/complex.js"); - -let suites_0 = [ - "basic_add", - param => ({ - TAG: "Eq", - _0: { - re: 2, - im: 2 - }, - _1: Complex.add(Complex.add(Complex.add(Complex.one, Complex.one), Complex.i), Complex.i) - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Complex_test", suites); - -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/complex_test.res b/jscomp/test/complex_test.res deleted file mode 100644 index ab34efa39d..0000000000 --- a/jscomp/test/complex_test.res +++ /dev/null @@ -1,8 +0,0 @@ -open Complex - -let suites = { - open Mt - list{("basic_add", _ => Eq({re: 2., im: 2.}, add(add(add(one, one), i), i)))} -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/demo_int_map.js b/jscomp/test/demo_int_map.js index 50052476dc..9355999c5b 100644 --- a/jscomp/test/demo_int_map.js +++ b/jscomp/test/demo_int_map.js @@ -1,167 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = x - v | 0; - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = x - param.v | 0; - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - find(i$1, m); + Belt_MapInt.get(m, i$1); } } diff --git a/jscomp/test/demo_int_map.res b/jscomp/test/demo_int_map.res index d2ec1f1905..d549afc645 100644 --- a/jscomp/test/demo_int_map.res +++ b/jscomp/test/demo_int_map.res @@ -1,16 +1,13 @@ -module IntMap = Map.Make({ - type t = int - let compare = (x: int, y) => x - y -}) +open Belt let test = () => { - let m = ref(IntMap.empty) + let m = ref(Map.Int.empty) let count = 1000_000 for i in 0 to count { - m := IntMap.add(i, i, m.contents) + m := m.contents->Map.Int.set(i, i) } for i in 0 to count { - ignore(IntMap.find(i, m.contents)) + m.contents->Map.Int.get(i)->ignore } } diff --git a/jscomp/test/es6_module_test.js b/jscomp/test/es6_module_test.js index 63507f8917..ef867e0329 100644 --- a/jscomp/test/es6_module_test.js +++ b/jscomp/test/es6_module_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function length(param) { return 3; @@ -13,7 +13,7 @@ Mt.from_pair_suites("Es6_module_test", { "list_length", () => ({ TAG: "Eq", - _0: List.length({ + _0: Belt_List.length({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/es6_module_test.res b/jscomp/test/es6_module_test.res index dbc4bd887f..5245fd4eb3 100644 --- a/jscomp/test/es6_module_test.res +++ b/jscomp/test/es6_module_test.res @@ -4,7 +4,7 @@ let length = _ => 3 Mt.from_pair_suites( __MODULE__, list{ - ("list_length", _ => Eq(List.length(list{1, 2}), 2)), + ("list_length", _ => Eq(Belt.List.length(list{1, 2}), 2)), ("length", _ => Eq(length(list{1, 2}), 3)), }, ) diff --git a/jscomp/test/event_ffi.js b/jscomp/test/event_ffi.js index 55421f3adb..1a92a6f004 100644 --- a/jscomp/test/event_ffi.js +++ b/jscomp/test/event_ffi.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function h0(x) { return x(); @@ -57,7 +57,7 @@ function xx() { }; } -let test_as = List.map; +let test_as = Belt_List.map; exports.h0 = h0; exports.h00 = h00; diff --git a/jscomp/test/event_ffi.res b/jscomp/test/event_ffi.res index 13d03efe6e..b5821c612f 100644 --- a/jscomp/test/event_ffi.res +++ b/jscomp/test/event_ffi.res @@ -59,7 +59,7 @@ let a3 = (x, y, z) => x + y + z /* let b44 () = Js.Internal.fn_mk4 (fun x y z d -> (x,y,z,d)) */ /* polymoprhic restriction */ -let test_as: ('a => 'a, _ as 'b) => 'b = List.map +let test_as: (_ as 'b, 'a => 'a) => 'b = Belt.List.map let xx: unit => _ => unit = () => _ => Js.log(3) diff --git a/jscomp/test/exception_alias.js b/jscomp/test/exception_alias.js index da3b52db8c..620e7f226b 100644 --- a/jscomp/test/exception_alias.js +++ b/jscomp/test/exception_alias.js @@ -1,13 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let a0 = { RE_EXN_ID: "Not_found" }; -let b = List.length({ +let b = Belt_List.length({ hd: 1, tl: { hd: 2, @@ -15,58 +15,94 @@ let b = List.length({ } }); -let List$1 = { - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, +let List = { + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort, b: b, length: 3 }; @@ -87,5 +123,5 @@ exports.a2 = a2; exports.a3 = a3; exports.a4 = a4; exports.a5 = a5; -exports.List = List$1; +exports.List = List; /* b Not a pure module */ diff --git a/jscomp/test/exception_alias.res b/jscomp/test/exception_alias.res index cdd03d5190..205b2c1d78 100644 --- a/jscomp/test/exception_alias.res +++ b/jscomp/test/exception_alias.res @@ -10,6 +10,8 @@ let a4 = a3 let a5 = a4 +open Belt + module List = { include List let b = length(list{1, 2}) diff --git a/jscomp/test/exception_raise_test.js b/jscomp/test/exception_raise_test.js index e847b09f39..d77198c5d4 100644 --- a/jscomp/test/exception_raise_test.js +++ b/jscomp/test/exception_raise_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); let Js_exn = require("../../lib/js/js_exn.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); @@ -214,7 +214,7 @@ function input_lines(ic, _acc) { try { line = input_line(ic); } catch (exn) { - return List.rev(acc); + return Belt_List.reverse(acc); } _acc = { hd: line, diff --git a/jscomp/test/exception_raise_test.res b/jscomp/test/exception_raise_test.res index bd1e269665..407bc1597e 100644 --- a/jscomp/test/exception_raise_test.res +++ b/jscomp/test/exception_raise_test.res @@ -150,7 +150,7 @@ type in_channel @val external input_line: in_channel => string = "input_line" let rec input_lines = (ic, acc) => switch input_line(ic) { - | exception _ => List.rev(acc) + | exception _ => Belt.List.reverse(acc) | line => input_lines(ic, list{line, ...acc}) } diff --git a/jscomp/test/global_module_alias_test.js b/jscomp/test/global_module_alias_test.js index f7708500b1..4e52e501c5 100644 --- a/jscomp/test/global_module_alias_test.js +++ b/jscomp/test/global_module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -45,10 +45,10 @@ function f() { v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; - return List; + return Belt_List; } -eq("File \"global_module_alias_test.res\", line 51, characters 12-19", List.length({ +eq("File \"global_module_alias_test.res\", line 53, characters 12-19", Belt_List.length({ hd: 1, tl: { hd: 2, @@ -80,12 +80,12 @@ v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; -let H = List; +let H = Belt_List; -eq("File \"global_module_alias_test.res\", line 55, characters 12-19", v.contents, 12); +eq("File \"global_module_alias_test.res\", line 57, characters 12-19", v.contents, 12); function g() { - return List.length({ + return Belt_List.length({ hd: 1, tl: { hd: 2, @@ -104,14 +104,14 @@ function xx() { v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; - return List; + return Belt_List; } -eq("File \"global_module_alias_test.res\", line 83, characters 12-19", g(), 4); +eq("File \"global_module_alias_test.res\", line 85, characters 12-19", g(), 4); let V = xx(); -eq("File \"global_module_alias_test.res\", line 87, characters 5-12", V.length({ +eq("File \"global_module_alias_test.res\", line 89, characters 5-12", V.length({ hd: 1, tl: { hd: 2, @@ -122,11 +122,11 @@ eq("File \"global_module_alias_test.res\", line 87, characters 5-12", V.length({ } }), 3); -eq("File \"global_module_alias_test.res\", line 88, characters 5-12", v.contents, 15); +eq("File \"global_module_alias_test.res\", line 90, characters 5-12", v.contents, 15); let H$1 = f(); -eq("File \"global_module_alias_test.res\", line 90, characters 5-12", H$1.length({ +eq("File \"global_module_alias_test.res\", line 92, characters 5-12", H$1.length({ hd: 1, tl: { hd: 2, @@ -134,7 +134,7 @@ eq("File \"global_module_alias_test.res\", line 90, characters 5-12", H$1.length } }), 2); -eq("File \"global_module_alias_test.res\", line 91, characters 5-12", v.contents, 21); +eq("File \"global_module_alias_test.res\", line 93, characters 5-12", v.contents, 21); Mt.from_pair_suites("Global_module_alias_test", suites.contents); diff --git a/jscomp/test/global_module_alias_test.res b/jscomp/test/global_module_alias_test.res index 485ad1b0f9..ba6bdad41e 100644 --- a/jscomp/test/global_module_alias_test.res +++ b/jscomp/test/global_module_alias_test.res @@ -1,3 +1,5 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { diff --git a/jscomp/test/gpr_1701_test.js b/jscomp/test/gpr_1701_test.js index dbf9f7c67a..2c5759dfa0 100644 --- a/jscomp/test/gpr_1701_test.js +++ b/jscomp/test/gpr_1701_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); @@ -48,7 +48,7 @@ function read_lines(inc) { } } if (l === undefined) { - return List.rev(acc); + return Belt_List.reverse(acc); } _acc = { hd: l, @@ -68,7 +68,7 @@ function read_lines2(inc) { } catch (raw_exn) { let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); if (exn.RE_EXN_ID === "End_of_file") { - return List.rev(acc); + return Belt_List.reverse(acc); } throw new Error(exn.RE_EXN_ID, { cause: exn @@ -93,7 +93,7 @@ function read_lines3(inc) { } catch (raw_exn) { let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); if (exn.RE_EXN_ID === "End_of_file") { - return List.rev(acc); + return Belt_List.reverse(acc); } throw new Error(exn.RE_EXN_ID, { cause: exn diff --git a/jscomp/test/gpr_1701_test.res b/jscomp/test/gpr_1701_test.res index ec95e04d28..371efe038b 100644 --- a/jscomp/test/gpr_1701_test.res +++ b/jscomp/test/gpr_1701_test.res @@ -1,3 +1,5 @@ +open Belt + exception Foo let rec test = n => @@ -20,7 +22,7 @@ let read_lines = inc => { | End_of_file => None } { | Some(l) => loop(list{l, ...acc}) - | None => List.rev(acc) + | None => List.reverse(acc) } loop(list{}) @@ -30,7 +32,7 @@ let read_lines2 = inc => { let rec loop = acc => switch input_line(inc) { | l => loop(list{l, ...acc}) - | exception End_of_file => List.rev(acc) + | exception End_of_file => List.reverse(acc) } loop(list{}) @@ -42,7 +44,7 @@ let read_lines3 = inc => { let l = input_line(inc) loop(list{l, ...acc}) } catch { - | End_of_file => List.rev(acc) + | End_of_file => List.reverse(acc) } loop(list{}) diff --git a/jscomp/test/gpr_2608_test.js b/jscomp/test/gpr_2608_test.js index f3a4853f53..94a1db8a63 100644 --- a/jscomp/test/gpr_2608_test.js +++ b/jscomp/test/gpr_2608_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -23,21 +23,21 @@ let oppHeroes = { let huntGrootCondition = false; -if (List.length(/* [] */0) > 0) { - let x = List.filter(h => List.hd(/* [] */0) <= 1000, oppHeroes); - huntGrootCondition = List.length(x) === 0; +if (Belt_List.length(/* [] */0) > 0) { + let x = Belt_List.filter(oppHeroes, h => Belt_List.headExn(/* [] */0) <= 1000); + huntGrootCondition = Belt_List.length(x) === 0; } let huntGrootCondition2 = true; -if (List.length(/* [] */0) < 0) { - let x$1 = List.filter(h => List.hd(/* [] */0) <= 1000, oppHeroes); - huntGrootCondition2 = List.length(x$1) === 0; +if (Belt_List.length(/* [] */0) < 0) { + let x$1 = Belt_List.filter(oppHeroes, h => Belt_List.headExn(/* [] */0) <= 1000); + huntGrootCondition2 = Belt_List.length(x$1) === 0; } -eq("File \"gpr_2608_test.res\", line 21, characters 5-12", huntGrootCondition, false); +eq("File \"gpr_2608_test.res\", line 23, characters 5-12", huntGrootCondition, false); -eq("File \"gpr_2608_test.res\", line 22, characters 5-12", huntGrootCondition2, true); +eq("File \"gpr_2608_test.res\", line 24, characters 5-12", huntGrootCondition2, true); Mt.from_pair_suites("Gpr_2608_test", suites.contents); diff --git a/jscomp/test/gpr_2608_test.res b/jscomp/test/gpr_2608_test.res index 65c23d0e56..a6f7947381 100644 --- a/jscomp/test/gpr_2608_test.res +++ b/jscomp/test/gpr_2608_test.res @@ -1,3 +1,5 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) @@ -7,13 +9,13 @@ let nearestGroots = list{} let oppHeroes = list{0} let huntGrootCondition = List.length(nearestGroots) > 0 && { - let x = List.filter(h => List.hd(nearestGroots) <= 1000, oppHeroes) + let x = oppHeroes->List.filter(h => List.headExn(nearestGroots) <= 1000) List.length(x) == 0 } let huntGrootCondition2 = List.length(nearestGroots) >= 0 || { - let x = List.filter(h => List.hd(nearestGroots) <= 1000, oppHeroes) + let x = oppHeroes->List.filter(h => List.headExn(nearestGroots) <= 1000) List.length(x) == 0 } diff --git a/jscomp/test/hello_res.js b/jscomp/test/hello_res.js index ee2ced30c1..1f2f16ad5a 100644 --- a/jscomp/test/hello_res.js +++ b/jscomp/test/hello_res.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); -let b = List.length({ +let b = Belt_List.length({ hd: 1, tl: { hd: 2, @@ -18,7 +18,7 @@ let a = b - 1 | 0; console.log("hello, res"); -List.length({ +Belt_List.length({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/hello_res.res b/jscomp/test/hello_res.res index e1e7fc96bb..040bdfaf48 100644 --- a/jscomp/test/hello_res.res +++ b/jscomp/test/hello_res.res @@ -4,6 +4,8 @@ ], }) +open Belt + let b = List.length(list{1, 2, 3}) let a = b - 1 Js.log("hello, res") @@ -17,13 +19,13 @@ let u: t = {"x": 3} let h = u["x"] -%%private(let {length, cons} = module(List)) +%%private(let {length, add} = module(List)) -%%private(let {length, cons} = module(List)) +%%private(let {length, add} = module(List)) %%private(let (a, b) = (1, 2)) -let {length: len, cons: c} = module(List) +let {length: len, add: c} = module(List) module H = { module H1 = { @@ -31,8 +33,8 @@ module H = { } } let u = { - let {length: l, cons} = module(List) - cons(l(list{1, 2, 3}), list{}) + let {length: l, add} = module(List) + list{}->add(l(list{1, 2, 3})) } let h = { diff --git a/jscomp/test/inline_map2_test.js b/jscomp/test/inline_map2_test.js index 18d66ce32e..7d02921f2f 100644 --- a/jscomp/test/inline_map2_test.js +++ b/jscomp/test/inline_map2_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Caml_option = require("../../lib/js/caml_option.js"); let Primitive_int = require("../../lib/js/primitive_int.js"); let Primitive_string = require("../../lib/js/primitive_string.js"); @@ -1302,7 +1302,7 @@ let IntMap = { choose: min_binding }; -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -1326,7 +1326,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); function height$1(x) { if (typeof x !== "object") { @@ -1993,7 +1993,7 @@ let SMap = { choose: min_binding$1 }; -let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", { +let s = Belt_List.reduceReverse({ hd: [ "10", /* 'a' */97 @@ -2017,7 +2017,7 @@ let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", } } } -}); +}, "Empty", (acc, param) => add$1(param[0], param[1], acc)); Mt.from_pair_suites("Inline_map2_test", { hd: [ diff --git a/jscomp/test/inline_map2_test.res b/jscomp/test/inline_map2_test.res index b9e0dcda19..ce07a4b912 100644 --- a/jscomp/test/inline_map2_test.res +++ b/jscomp/test/inline_map2_test.res @@ -455,21 +455,20 @@ module IntMap = Make({ let empty = IntMap.empty -let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => IntMap.add(k, v, acc)) module SMap = Make({ type t = string let compare = (x: t, y) => compare(x, y) }) -let s = List.fold_left( - (acc, (k, v)) => SMap.add(k, v, acc), - SMap.empty, +let s = Belt.List.reduceReverse( list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, + SMap.empty, + (acc, (k, v)) => SMap.add(k, v, acc), ) @val("console.log") external log: 'a => unit = "" diff --git a/jscomp/test/inline_map_demo.js b/jscomp/test/inline_map_demo.js index 0645080c24..38926b87a6 100644 --- a/jscomp/test/inline_map_demo.js +++ b/jscomp/test/inline_map_demo.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Primitive_int = require("../../lib/js/primitive_int.js"); function height(x) { @@ -141,7 +141,7 @@ function add(x, data, tree) { } } -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -165,7 +165,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); function find(px, _x) { while (true) { diff --git a/jscomp/test/inline_map_demo.res b/jscomp/test/inline_map_demo.res index 9360771940..78877b5bc3 100644 --- a/jscomp/test/inline_map_demo.res +++ b/jscomp/test/inline_map_demo.res @@ -111,11 +111,10 @@ let empty = Empty No assumption on the heights of l and r. */ /* end */ -let m = List.fold_left( - (acc, (k, v)) => add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => add(k, v, acc)) let rec find = (px, x) => switch x { diff --git a/jscomp/test/inline_map_test.js b/jscomp/test/inline_map_test.js index 1cac459637..c2f5cc40f3 100644 --- a/jscomp/test/inline_map_test.js +++ b/jscomp/test/inline_map_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Primitive_int = require("../../lib/js/primitive_int.js"); function height(x) { @@ -144,7 +144,7 @@ function find(x, _x_) { }; } -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -168,7 +168,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); Mt.from_pair_suites("Inline_map_test", { hd: [ diff --git a/jscomp/test/inline_map_test.res b/jscomp/test/inline_map_test.res index 01368d7500..927babcfe3 100644 --- a/jscomp/test/inline_map_test.res +++ b/jscomp/test/inline_map_test.res @@ -405,11 +405,10 @@ let bindings = s => bindings_aux(list{}, s) let choose = min_binding /* end */ -let m = List.fold_left( - (acc, (k, v)) => add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => add(k, v, acc)) @val("console.log") external log: 'a => unit = "" diff --git a/jscomp/test/inline_record_test.js b/jscomp/test/inline_record_test.js index b6e71324b1..dccce21492 100644 --- a/jscomp/test/inline_record_test.js +++ b/jscomp/test/inline_record_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); let suites = { @@ -36,9 +36,9 @@ let v1 = { function f(x) { if (x.TAG === "A0") { - return List.fold_left((prim0, prim1) => prim0 + prim1 | 0, x.lbl, x.more); + return Belt_List.reduceReverse(x.more, x.lbl, (prim0, prim1) => prim0 + prim1 | 0); } else { - return List.fold_left((prim0, prim1) => prim0 + prim1 | 0, 0, x.more); + return Belt_List.reduceReverse(x.more, 0, (prim0, prim1) => prim0 + prim1 | 0); } } diff --git a/jscomp/test/inline_record_test.res b/jscomp/test/inline_record_test.res index cfc5b2430c..26e8a9d594 100644 --- a/jscomp/test/inline_record_test.res +++ b/jscomp/test/inline_record_test.res @@ -13,8 +13,8 @@ let v1 = A1({more: list{1, 2}}) let f = (x: t0) => switch x { - | A0({lbl, more}) => List.fold_left(\"+", lbl, more) - | A1({more}) => List.fold_left(\"+", 0, more) + | A0({lbl, more}) => more->Belt.List.reduceReverse(lbl, \"+") + | A1({more}) => more->Belt.List.reduceReverse(0, \"+") } eq(__LOC__, f(v), 3) eq(__LOC__, f(v1), 3) diff --git a/jscomp/test/inner_unused.js b/jscomp/test/inner_unused.js index 9f4fb403b8..b938658dc5 100644 --- a/jscomp/test/inner_unused.js +++ b/jscomp/test/inner_unused.js @@ -6,7 +6,7 @@ function f(x) { return x + 3 | 0; } -function M(S) { +function M(Id) { let f = x => x; return { f: f diff --git a/jscomp/test/inner_unused.res b/jscomp/test/inner_unused.res index 5c70a3aab0..75c8dfd985 100644 --- a/jscomp/test/inner_unused.res +++ b/jscomp/test/inner_unused.res @@ -7,7 +7,7 @@ let f = x => { x + 3 } -module M = (S: Set.S): { +module M = (Id: Belt.Id.Comparable): { let f: int => int } => { let f = x => x diff --git a/jscomp/test/int_map.js b/jscomp/test/int_map.js index e939cab355..3960046308 100644 --- a/jscomp/test/int_map.js +++ b/jscomp/test/int_map.js @@ -1,1004 +1,24 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); -let Primitive_int = require("../../lib/js/primitive_int.js"); +let Belt_Map = require("../../lib/js/belt_Map.js"); +let Caml_obj = require("../../lib/js/caml_obj.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} +let cmp = Caml_obj.compare; -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} +let IntCmp = { + cmp: cmp +}; -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} +let m_cmp = IntCmp.cmp; -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} +let m = { + cmp: m_cmp, + data: undefined +}; -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} +let m$1 = Belt_Map.set(m, 0, "test"); -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_int.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let empty = "Empty"; - -let choose = min_binding; - -let choose_opt = min_binding_opt; - -exports.empty = empty; -exports.is_empty = is_empty; -exports.mem = mem; -exports.add = add; -exports.update = update; -exports.singleton = singleton; -exports.remove = remove; -exports.merge = merge$1; -exports.union = union; -exports.compare = compare; -exports.equal = equal; -exports.iter = iter; -exports.fold = fold; -exports.for_all = for_all; -exports.exists = exists; -exports.filter = filter; -exports.partition = partition; -exports.cardinal = cardinal; -exports.bindings = bindings; -exports.min_binding = min_binding; -exports.min_binding_opt = min_binding_opt; -exports.max_binding = max_binding; -exports.max_binding_opt = max_binding_opt; -exports.choose = choose; -exports.choose_opt = choose_opt; -exports.split = split; -exports.find = find; -exports.find_opt = find_opt; -exports.find_first = find_first; -exports.find_first_opt = find_first_opt; -exports.find_last = find_last; -exports.find_last_opt = find_last_opt; -exports.map = map; -exports.mapi = mapi; -/* No side effect */ +exports.IntCmp = IntCmp; +exports.m = m$1; +/* IntCmp Not a pure module */ diff --git a/jscomp/test/int_map.res b/jscomp/test/int_map.res index 223b4797b4..a3834063f3 100644 --- a/jscomp/test/int_map.res +++ b/jscomp/test/int_map.res @@ -1,4 +1,7 @@ -include Map.Make({ +module IntCmp = Belt.Id.MakeComparable({ type t = int - let compare = (x: int, y) => compare(x, y) + let cmp = (a, b) => Pervasives.compare(a, b) }) + +let m = Belt.Map.make(~id=module(IntCmp)) +let m = m->Belt.Map.set(0, "test") diff --git a/jscomp/test/libqueue_test.js b/jscomp/test/libqueue_test.js deleted file mode 100644 index 693731383c..0000000000 --- a/jscomp/test/libqueue_test.js +++ /dev/null @@ -1,1470 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Queue = require("../../lib/js/queue.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function to_list(q) { - return List.rev(Queue.fold((l, x) => ({ - hd: x, - tl: l - }), /* [] */0, q)); -} - -let Q = { - Empty: Queue.Empty, - create: Queue.create, - add: Queue.add, - push: Queue.push, - take: Queue.take, - pop: Queue.pop, - peek: Queue.peek, - top: Queue.top, - clear: Queue.clear, - copy: Queue.copy, - is_empty: Queue.is_empty, - length: Queue.length, - iter: Queue.iter, - fold: Queue.fold, - transfer: Queue.transfer, - to_list: to_list -}; - -function does_raise(f, q) { - try { - f(q); - return false; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Queue.Empty) { - return true; - } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); - } -} - -let q = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (!(to_list(q) === /* [] */0 && q.length === 0)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 30, - 2 - ] - } - }); -} - -Queue.add(1, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: /* [] */0 - }) && q.length === 1)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 32, - 2 - ] - } - }); -} - -Queue.add(2, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }) && q.length === 2)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 34, - 2 - ] - } - }); -} - -Queue.add(3, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }) && q.length === 3)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 36, - 2 - ] - } - }); -} - -Queue.add(4, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }) && q.length === 4)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 38, - 2 - ] - } - }); -} - -if (Queue.take(q) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 39, - 2 - ] - } - }); -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - }) && q.length === 3)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 40, - 2 - ] - } - }); -} - -if (Queue.take(q) !== 2) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 41, - 2 - ] - } - }); -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }) && q.length === 2)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 42, - 2 - ] - } - }); -} - -if (Queue.take(q) !== 3) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 43, - 2 - ] - } - }); -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 4, - tl: /* [] */0 - }) && q.length === 1)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 44, - 2 - ] - } - }); -} - -if (Queue.take(q) !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 45, - 2 - ] - } - }); -} - -if (!(to_list(q) === /* [] */0 && q.length === 0)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 46, - 2 - ] - } - }); -} - -if (!does_raise(Queue.take, q)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 47, - 2 - ] - } - }); -} - -let q$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -Queue.add(1, q$1); - -if (Queue.take(q$1) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 53, - 2 - ] - } - }); -} - -if (!does_raise(Queue.take, q$1)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 54, - 2 - ] - } - }); -} - -Queue.add(2, q$1); - -if (Queue.take(q$1) !== 2) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 56, - 2 - ] - } - }); -} - -if (!does_raise(Queue.take, q$1)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 57, - 2 - ] - } - }); -} - -if (q$1.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 58, - 2 - ] - } - }); -} - -let q$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -Queue.add(1, q$2); - -if (Queue.peek(q$2) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 64, - 2 - ] - } - }); -} - -Queue.add(2, q$2); - -if (Queue.peek(q$2) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 66, - 2 - ] - } - }); -} - -Queue.add(3, q$2); - -if (Queue.peek(q$2) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 68, - 2 - ] - } - }); -} - -if (Queue.peek(q$2) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 69, - 2 - ] - } - }); -} - -if (Queue.take(q$2) !== 1) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 70, - 2 - ] - } - }); -} - -if (Queue.peek(q$2) !== 2) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 71, - 2 - ] - } - }); -} - -if (Queue.take(q$2) !== 2) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 72, - 2 - ] - } - }); -} - -if (Queue.peek(q$2) !== 3) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 73, - 2 - ] - } - }); -} - -if (Queue.take(q$2) !== 3) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 74, - 2 - ] - } - }); -} - -if (!does_raise(Queue.peek, q$2)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 75, - 2 - ] - } - }); -} - -if (!does_raise(Queue.peek, q$2)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 76, - 2 - ] - } - }); -} - -let q$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i = 1; i <= 10; ++i) { - Queue.add(i, q$3); -} - -Queue.clear(q$3); - -if (q$3.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 85, - 2 - ] - } - }); -} - -if (!does_raise(Queue.take, q$3)) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 86, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(q$3, { - length: 0, - first: "Nil", - last: "Nil" - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 87, - 2 - ] - } - }); -} - -Queue.add(42, q$3); - -if (Queue.take(q$3) !== 42) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 89, - 2 - ] - } - }); -} - -let q1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$1 = 1; i$1 <= 10; ++i$1) { - Queue.add(i$1, q1); -} - -let q2 = Queue.copy(q1); - -if (!Caml_obj.equal(to_list(q1), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 98, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 99, - 2 - ] - } - }); -} - -if (q1.length !== 10) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 100, - 2 - ] - } - }); -} - -if (q2.length !== 10) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 101, - 2 - ] - } - }); -} - -for (let i$2 = 1; i$2 <= 10; ++i$2) { - if (Queue.take(q1) !== i$2) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 103, - 4 - ] - } - }); - } - -} - -for (let i$3 = 1; i$3 <= 10; ++i$3) { - if (Queue.take(q2) !== i$3) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 106, - 4 - ] - } - }); - } - -} - -let q$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (q$4.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 112, - 2 - ] - } - }); -} - -for (let i$4 = 1; i$4 <= 10; ++i$4) { - Queue.add(i$4, q$4); - if (q$4.length !== i$4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 115, - 4 - ] - } - }); - } - if (q$4.length === 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 116, - 4 - ] - } - }); - } - -} - -for (let i$5 = 10; i$5 >= 1; --i$5) { - if (q$4.length !== i$5) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 119, - 4 - ] - } - }); - } - if (q$4.length === 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 120, - 4 - ] - } - }); - } - Queue.take(q$4); -} - -if (q$4.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 123, - 2 - ] - } - }); -} - -if (q$4.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 124, - 2 - ] - } - }); -} - -let q$5 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$6 = 1; i$6 <= 10; ++i$6) { - Queue.add(i$6, q$5); -} - -let i$7 = { - contents: 1 -}; - -Queue.iter(j => { - if (i$7.contents !== j) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 134, - 4 - ] - } - }); - } - i$7.contents = i$7.contents + 1 | 0; -}, q$5); - -let q1$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (q1$1.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 141, - 2 - ] - } - }); -} - -if (to_list(q1$1) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 142, - 2 - ] - } - }); -} - -if (q2$1.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 143, - 2 - ] - } - }); -} - -if (to_list(q2$1) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 144, - 2 - ] - } - }); -} - -Queue.transfer(q1$1, q2$1); - -if (q1$1.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 146, - 2 - ] - } - }); -} - -if (to_list(q1$1) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 147, - 2 - ] - } - }); -} - -if (q2$1.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 148, - 2 - ] - } - }); -} - -if (to_list(q2$1) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 149, - 2 - ] - } - }); -} - -let q1$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$8 = 1; i$8 <= 4; ++i$8) { - Queue.add(i$8, q1$2); -} - -if (q1$2.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 157, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 158, - 2 - ] - } - }); -} - -if (q2$2.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 159, - 2 - ] - } - }); -} - -if (to_list(q2$2) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 160, - 2 - ] - } - }); -} - -Queue.transfer(q1$2, q2$2); - -if (q1$2.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 162, - 2 - ] - } - }); -} - -if (to_list(q1$2) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 163, - 2 - ] - } - }); -} - -if (q2$2.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 164, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 165, - 2 - ] - } - }); -} - -let q1$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$9 = 5; i$9 <= 8; ++i$9) { - Queue.add(i$9, q2$3); -} - -if (q1$3.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 173, - 2 - ] - } - }); -} - -if (to_list(q1$3) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 174, - 2 - ] - } - }); -} - -if (q2$3.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 175, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2$3), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 176, - 2 - ] - } - }); -} - -Queue.transfer(q1$3, q2$3); - -if (q1$3.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 178, - 2 - ] - } - }); -} - -if (to_list(q1$3) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 179, - 2 - ] - } - }); -} - -if (q2$3.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 180, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2$3), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 181, - 2 - ] - } - }); -} - -let q1$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$10 = 1; i$10 <= 4; ++i$10) { - Queue.add(i$10, q1$4); -} - -for (let i$11 = 5; i$11 <= 8; ++i$11) { - Queue.add(i$11, q2$4); -} - -if (q1$4.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 192, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q1$4), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 193, - 2 - ] - } - }); -} - -if (q2$4.length !== 4) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 194, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2$4), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 195, - 2 - ] - } - }); -} - -Queue.transfer(q1$4, q2$4); - -if (q1$4.length !== 0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 197, - 2 - ] - } - }); -} - -if (to_list(q1$4) !== /* [] */0) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 198, - 2 - ] - } - }); -} - -if (q2$4.length !== 8) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 199, - 2 - ] - } - }); -} - -if (!Caml_obj.equal(to_list(q2$4), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - } - } - } - })) { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 200, - 2 - ] - } - }); -} - -console.log("OK"); - -exports.Q = Q; -exports.does_raise = does_raise; -/* q Not a pure module */ diff --git a/jscomp/test/libqueue_test.res b/jscomp/test/libqueue_test.res deleted file mode 100644 index 4c8b24c4b8..0000000000 --- a/jscomp/test/libqueue_test.res +++ /dev/null @@ -1,203 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2015 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the Q Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -module Q = { - include Queue - - let to_list = q => List.rev(fold((l, x) => list{x, ...l}, list{}, q)) -} - -let does_raise = (f, q) => - try { - ignore((f(q): int)) - false - } catch { - | Q.Empty => true - } - -let () = { - let q = Q.create() - () - assert(Q.to_list(q) == list{} && Q.length(q) == 0) - Q.add(1, q) - assert(Q.to_list(q) == list{1} && Q.length(q) == 1) - Q.add(2, q) - assert(Q.to_list(q) == list{1, 2} && Q.length(q) == 2) - Q.add(3, q) - assert(Q.to_list(q) == list{1, 2, 3} && Q.length(q) == 3) - Q.add(4, q) - assert(Q.to_list(q) == list{1, 2, 3, 4} && Q.length(q) == 4) - assert(Q.take(q) == 1) - assert(Q.to_list(q) == list{2, 3, 4} && Q.length(q) == 3) - assert(Q.take(q) == 2) - assert(Q.to_list(q) == list{3, 4} && Q.length(q) == 2) - assert(Q.take(q) == 3) - assert(Q.to_list(q) == list{4} && Q.length(q) == 1) - assert(Q.take(q) == 4) - assert(Q.to_list(q) == list{} && Q.length(q) == 0) - assert(does_raise(Q.take, q)) -} - -let () = { - let q = Q.create() - Q.add(1, q) - assert(Q.take(q) == 1) - assert(does_raise(Q.take, q)) - Q.add(2, q) - assert(Q.take(q) == 2) - assert(does_raise(Q.take, q)) - assert(Q.length(q) == 0) -} - -let () = { - let q = Q.create() - Q.add(1, q) - assert(Q.peek(q) == 1) - Q.add(2, q) - assert(Q.peek(q) == 1) - Q.add(3, q) - assert(Q.peek(q) == 1) - assert(Q.peek(q) == 1) - assert(Q.take(q) == 1) - assert(Q.peek(q) == 2) - assert(Q.take(q) == 2) - assert(Q.peek(q) == 3) - assert(Q.take(q) == 3) - assert(does_raise(Q.peek, q)) - assert(does_raise(Q.peek, q)) -} - -let () = { - let q = Q.create() - for i in 1 to 10 { - Q.add(i, q) - } - Q.clear(q) - assert(Q.length(q) == 0) - assert(does_raise(Q.take, q)) - assert(q == Q.create()) - Q.add(42, q) - assert(Q.take(q) == 42) -} - -let () = { - let q1 = Q.create() - for i in 1 to 10 { - Q.add(i, q1) - } - let q2 = Q.copy(q1) - assert(Q.to_list(q1) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert(Q.to_list(q2) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert(Q.length(q1) == 10) - assert(Q.length(q2) == 10) - for i in 1 to 10 { - assert(Q.take(q1) == i) - } - for i in 1 to 10 { - assert(Q.take(q2) == i) - } -} - -let () = { - let q = Q.create() - assert(Q.is_empty(q)) - for i in 1 to 10 { - Q.add(i, q) - assert(Q.length(q) == i) - assert(!Q.is_empty(q)) - } - for i in 10 downto 1 { - assert(Q.length(q) == i) - assert(!Q.is_empty(q)) - ignore((Q.take(q): int)) - } - assert(Q.length(q) == 0) - assert(Q.is_empty(q)) -} - -let () = { - let q = Q.create() - for i in 1 to 10 { - Q.add(i, q) - } - let i = ref(1) - Q.iter(j => { - assert(i.contents == j) - incr(i) - }, q) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 1 to 4 { - Q.add(i, q1) - } - assert(Q.length(q1) == 4) - assert(Q.to_list(q1) == list{1, 2, 3, 4}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{1, 2, 3, 4}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 5 to 8 { - Q.add(i, q2) - } - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 1 to 4 { - Q.add(i, q1) - } - for i in 5 to 8 { - Q.add(i, q2) - } - assert(Q.length(q1) == 4) - assert(Q.to_list(q1) == list{1, 2, 3, 4}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 8) - assert(Q.to_list(q2) == list{5, 6, 7, 8, 1, 2, 3, 4}) -} - -let () = Js.log("OK") diff --git a/jscomp/test/list_stack.js b/jscomp/test/list_stack.js deleted file mode 100644 index 23e5faacef..0000000000 --- a/jscomp/test/list_stack.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -List.find(x => x > 3, /* [] */0); - -/* Not a pure module */ diff --git a/jscomp/test/list_stack.res b/jscomp/test/list_stack.res deleted file mode 100644 index 483e4b0908..0000000000 --- a/jscomp/test/list_stack.res +++ /dev/null @@ -1 +0,0 @@ -List.find(x => x > 3, list{})->ignore diff --git a/jscomp/test/map_find_test.js b/jscomp/test/map_find_test.js index a97e355561..3cd748cb7a 100644 --- a/jscomp/test/map_find_test.js +++ b/jscomp/test/map_find_test.js @@ -2,164 +2,11 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Primitive_int = require("../../lib/js/primitive_int.js"); -let Primitive_string = require("../../lib/js/primitive_string.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); +let Belt_MapString = require("../../lib/js/belt_MapString.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -183,162 +30,9 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); - -function height$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create$1(l, x, d, r) { - let hl = height$1(l); - let hr = height$1(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal$1(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height$1(ll) >= height$1(lr)) { - return create$1(ll, lv, ld, create$1(lr, x, d, r)); - } - if (typeof lr === "object") { - return create$1(create$1(ll, lv, ld, lr.l), lr.v, lr.d, create$1(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height$1(rr) >= height$1(rl)) { - return create$1(create$1(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create$1(create$1(l, x, d, rl.l), rl.v, rl.d, create$1(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function add$1(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add$1(x, data, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = add$1(x, data, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function find$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} +}, undefined, (acc, param) => Belt_MapInt.set(acc, param[0], param[1])); -let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", { +let s = Belt_List.reduceReverse({ hd: [ "10", /* 'a' */97 @@ -362,14 +56,14 @@ let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", } } } -}); +}, undefined, (acc, param) => Belt_MapString.set(acc, param[0], param[1])); Mt.from_pair_suites("Map_find_test", { hd: [ "int", () => ({ TAG: "Eq", - _0: find(10, m), + _0: Belt_MapInt.get(m, 10), _1: /* 'a' */97 }) ], @@ -378,7 +72,7 @@ Mt.from_pair_suites("Map_find_test", { "string", () => ({ TAG: "Eq", - _0: find$1("10", s), + _0: Belt_MapString.get(s, "10"), _1: /* 'a' */97 }) ], diff --git a/jscomp/test/map_find_test.res b/jscomp/test/map_find_test.res index 43cf4300f8..0f5c367623 100644 --- a/jscomp/test/map_find_test.res +++ b/jscomp/test/map_find_test.res @@ -1,33 +1,30 @@ +open Belt + include ( { - module IntMap = Map.Make({ - type t = int - let compare = (x: t, y) => compare(x, y) - }) + module IntMap = Map.Int let empty = IntMap.empty - let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, - ) + let m = List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), + ) => acc->IntMap.set(k, v)) - module SMap = Map.Make({ - type t = string - let compare = (x: t, y) => compare(x, y) - }) + module SMap = Map.String - let s = List.fold_left( - (acc, (k, v)) => SMap.add(k, v, acc), - SMap.empty, - list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, - ) + let s = List.reduceReverse(list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, SMap.empty, ( + acc, + (k, v), + ) => acc->SMap.set(k, v)) @val("console.log") external log: 'a => unit = "" \"@@"( Mt.from_pair_suites(__MODULE__, ...), - list{("int", _ => Eq(IntMap.find(10, m), 'a')), ("string", _ => Eq(SMap.find("10", s), 'a'))} + list{ + ("int", _ => Eq(IntMap.get(m, 10), Some('a'))), + ("string", _ => Eq(SMap.get(s, "10"), Some('a'))), + } ) }: {} ) diff --git a/jscomp/test/map_test.js b/jscomp/test/map_test.js deleted file mode 100644 index 88bf591003..0000000000 --- a/jscomp/test/map_test.js +++ /dev/null @@ -1,2175 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Primitive_int = require("../../lib/js/primitive_int.js"); -let Primitive_string = require("../../lib/js/primitive_string.js"); - -let compare = Primitive_int.compare; - -let Int = { - compare: compare -}; - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare$1(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_int.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let Int_map = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare$1, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; - -function height$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create$1(l, x, d, r) { - let hl = height$1(l); - let hr = height$1(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton$1(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal$1(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height$1(ll) >= height$1(lr)) { - return create$1(ll, lv, ld, create$1(lr, x, d, r)); - } - if (typeof lr === "object") { - return create$1(create$1(ll, lv, ld, lr.l), lr.v, lr.d, create$1(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height$1(rr) >= height$1(rl)) { - return create$1(create$1(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create$1(create$1(l, x, d, rl.l), rl.v, rl.d, create$1(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function is_empty$1(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add$1(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add$1(x, data, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = add$1(x, data, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function find$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding$1(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal$1(remove_min_binding$1(l), param.v, param.d, param.r); - } -} - -function merge$2(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding$1(t2); - return bal$1(t1, match[0], match[1], remove_min_binding$1(t2)); -} - -function remove$1(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return merge$2(l, r); - } - if (c < 0) { - let ll = remove$1(x, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = remove$1(x, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function update$1(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge$2(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update$1(x, f, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = update$1(x, f, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function iter$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter$1(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map$1(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map$1(f, param.l); - let d$p = f(param.d); - let r$p = map$1(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi$1(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi$1(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi$1(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold$1(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold$1(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all$1(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all$1(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists$1(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists$1(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding$1(k, x, param) { - if (typeof param !== "object") { - return singleton$1(k, x); - } else { - return bal$1(add_min_binding$1(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding$1(k, x, param) { - if (typeof param !== "object") { - return singleton$1(k, x); - } else { - return bal$1(param.l, param.v, param.d, add_max_binding$1(k, x, param.r)); - } -} - -function join$1(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding$1(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding$1(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal$1(l.l, l.v, l.d, join$1(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal$1(join$1(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create$1(l, v, d, r); - } -} - -function concat$1(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding$1(t2); - return join$1(t1, match[0], match[1], remove_min_binding$1(t2)); -} - -function concat_or_join$1(t1, v, d, t2) { - if (d !== undefined) { - return join$1(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat$1(t1, t2); - } -} - -function split$1(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split$1(x, l); - return [ - match[0], - match[1], - join$1(match[2], v, d, r) - ]; - } - let match$1 = split$1(x, r); - return [ - join$1(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$3(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height$1(s2)) { - let match = split$1(v1, s2); - return concat_or_join$1(merge$3(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$3(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split$1(v2, s1); - return concat_or_join$1(merge$3(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$3(f, match$1[2], s2.r)); -} - -function union$1(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split$1(v1, s2); - let d2$1 = match[1]; - let l = union$1(f, s1.l, match[0]); - let r = union$1(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join$1(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join$1(l, v1, d1, r); - } - } - let match$1 = split$1(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union$1(f, match$1[0], s2.l); - let r$1 = union$1(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join$1(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join$1(l$1, v2, d2, r$1); - } -} - -function filter$1(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter$1(p, l); - let pvd = p(v, d); - let r$p = filter$1(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join$1(l$p, v, d, r$p); - } - } else { - return concat$1(l$p, r$p); - } -} - -function partition$1(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition$1(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition$1(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join$1(lt, v, d, rt), - concat$1(lf, rf) - ]; - } else { - return [ - concat$1(lt, rt), - join$1(lf, v, d, rf) - ]; - } -} - -function cons_enum$1(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare$2(cmp, m1, m2) { - let _e1 = cons_enum$1(m1, "End"); - let _e2 = cons_enum$1(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_string.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum$1(e2._2, e2._3); - _e1 = cons_enum$1(e1._2, e1._3); - continue; - }; -} - -function equal$1(cmp, m1, m2) { - let _e1 = cons_enum$1(m1, "End"); - let _e2 = cons_enum$1(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum$1(e2._2, e2._3); - _e1 = cons_enum$1(e1._2, e1._3); - continue; - }; -} - -function cardinal$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal$1(param.l) + 1 | 0) + cardinal$1(param.r) | 0; - } -} - -function bindings_aux$1(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux$1(accu, param.r) - }; - continue; - }; -} - -function bindings$1(s) { - return bindings_aux$1(/* [] */0, s); -} - -let String_map = { - empty: "Empty", - is_empty: is_empty$1, - mem: mem$1, - add: add$1, - update: update$1, - singleton: singleton$1, - remove: remove$1, - merge: merge$3, - union: union$1, - compare: compare$2, - equal: equal$1, - iter: iter$1, - fold: fold$1, - for_all: for_all$1, - exists: exists$1, - filter: filter$1, - partition: partition$1, - cardinal: cardinal$1, - bindings: bindings$1, - min_binding: min_binding$1, - min_binding_opt: min_binding_opt$1, - max_binding: max_binding$1, - max_binding_opt: max_binding_opt$1, - choose: min_binding$1, - choose_opt: min_binding_opt$1, - split: split$1, - find: find$1, - find_opt: find_opt$1, - find_first: find_first$1, - find_first_opt: find_first_opt$1, - find_last: find_last$1, - find_last_opt: find_last_opt$1, - map: map$1, - mapi: mapi$1 -}; - -function of_list(kvs) { - return List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", kvs); -} - -let int_map_suites_0 = [ - "add", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: cardinal(v), - _1: 3 - }; - } -]; - -let int_map_suites_1 = { - hd: [ - "equal", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - let u = of_list({ - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: { - hd: [ - 1, - /* '1' */49 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: compare$1(Primitive_int.compare, u, v), - _1: 0 - }; - } - ], - tl: { - hd: [ - "equal2", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - let u = of_list({ - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: { - hd: [ - 1, - /* '1' */49 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: true, - _1: equal((x, y) => x === y, u, v) - }; - } - ], - tl: { - hd: [ - "iteration", - param => { - let m = "Empty"; - for (let i = 0; i <= 10000; ++i) { - m = add$1(i.toString(), i.toString(), m); - } - let v = -1; - for (let i$1 = 0; i$1 <= 10000; ++i$1) { - if (find$1(i$1.toString(), m) !== i$1.toString()) { - v = i$1; - } - - } - return { - TAG: "Eq", - _0: v, - _1: -1 - }; - } - ], - tl: /* [] */0 - } - } -}; - -let int_map_suites = { - hd: int_map_suites_0, - tl: int_map_suites_1 -}; - -Mt.from_pair_suites("Map_test", int_map_suites); - -exports.Int = Int; -exports.Int_map = Int_map; -exports.String_map = String_map; -exports.of_list = of_list; -exports.int_map_suites = int_map_suites; -/* Not a pure module */ diff --git a/jscomp/test/map_test.res b/jscomp/test/map_test.res deleted file mode 100644 index 069489e804..0000000000 --- a/jscomp/test/map_test.res +++ /dev/null @@ -1,57 +0,0 @@ -open Mt -module Int = { - type t = int - let compare = (x: int, y: int) => Pervasives.compare(x, y) -} -module Int_map = Map.Make(Int) -module String_map = Map.Make(String) - -let of_list = kvs => List.fold_left((acc, (k, v)) => Int_map.add(k, v, acc), Int_map.empty, kvs) - -let int_map_suites = { - open Mt - open Int_map - list{ - ( - "add", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - Eq(cardinal(v), 3) - }, - ), - ( - "equal", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - let u = of_list(list{(2, '3'), (3, '4'), (1, '1')}) - Eq(compare(Pervasives.compare, u, v), 0) - }, - ), - ( - "equal2", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - let u = of_list(list{(2, '3'), (3, '4'), (1, '1')}) - Eq(true, equal((x, y) => x == y, u, v)) - }, - ), - ( - "iteration", - _ => { - let m = ref(String_map.empty) - let count = 1_0000 - for i in 0 to count { - m := String_map.add(Js.Int.toString(i), Js.Int.toString(i), m.contents) - } - let v = ref(-1) - for i in 0 to count { - if String_map.find(Js.Int.toString(i), m.contents) !== Js.Int.toString(i) { - v := i - } - } - Eq(v.contents, -1) - }, - ), - } -} -Mt.from_pair_suites(__MODULE__, int_map_suites) diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index fcc2d3e9e7..2622fcc601 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -1,8 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Caml_option = require("../../lib/js/caml_option.js"); let Primitive_int = require("../../lib/js/primitive_int.js"); @@ -961,7 +961,7 @@ function update_player(player, keys, context) { let prev_jumping = player.jumping; let prev_dir = player.dir; let prev_vx = Math.abs(player.vel.x); - List.iter(extra => { + Belt_List.forEach(keys, extra => { let lr_acc = player.vel.x * 0.2; switch (extra) { case "CLeft" : @@ -1001,7 +1001,7 @@ function update_player(player, keys, context) { return; } } - }, keys); + }); let v = player.vel.x * 0.9; let vel_damped = Math.abs(v) < 0.1 ? 0 : v; player.vel.x = vel_damped; @@ -2098,13 +2098,13 @@ function process_collision(dir, c1, c2, state) { function broad_phase(collid, all_collids, state) { let obj = collid._2; - return List.filter(c => { + return Belt_List.filter(all_collids, c => { if (in_viewport(state.vpt, obj.pos) || is_player(collid)) { return true; } else { return out_of_viewport_below(state.vpt, obj.pos.y); } - }, all_collids); + }); } function check_collisions(collid, all_collids, state) { @@ -2218,7 +2218,7 @@ function translate_keys() { hd: ctrls_0, tl: ctrls_1 }; - return List.fold_left((a, x) => { + return Belt_List.reduceReverse(ctrls, /* [] */0, (a, x) => { if (x[0]) { return { hd: x[1], @@ -2227,7 +2227,7 @@ function translate_keys() { } else { return a; } - }, /* [] */0, ctrls); + }); } function run_update_collid(state, collid, all_collids) { @@ -2312,10 +2312,10 @@ function update_loop(canvas, param, map_dim) { multiplier: state.multiplier, game_over: state.game_over }; - List.iter(obj => { + Belt_List.forEach(objs, obj => { run_update_collid(state$1, obj, objs); - }, objs); - List.iter(part => { + }); + Belt_List.forEach(parts, part => { process(part); let x = part.pos.x - state$1.vpt.pos.x; let y = part.pos.y - state$1.vpt.pos.y; @@ -2331,7 +2331,7 @@ function update_loop(canvas, param, map_dim) { return; } - }, parts); + }); fps(canvas, fps$1); hud(canvas, state$1.score, state$1.coins); requestAnimationFrame(t => update_helper(t, state$1, player$1, collid_objs.contents, particles.contents)); @@ -3317,15 +3317,7 @@ function inc_counter(param) { } function preload(param) { - return List.map(img_src => { - let img_src$1 = "sprites/" + img_src; - let img = document.createElement("img"); - img.src = img_src$1; - img.addEventListener("load", ev => { - inc_counter(); - return true; - }, true); - }, { + return Belt_List.map({ hd: "blocks.png", tl: { hd: "items.png", @@ -3337,6 +3329,14 @@ function preload(param) { } } } + }, img_src => { + let img_src$1 = "sprites/" + img_src; + let img = document.createElement("img"); + img.src = img_src$1; + img.addEventListener("load", ev => { + inc_counter(); + return true; + }, true); }); } diff --git a/jscomp/test/mario_game.res b/jscomp/test/mario_game.res index 2def5261b7..28916eb705 100644 --- a/jscomp/test/mario_game.res +++ b/jscomp/test/mario_game.res @@ -1,5 +1,7 @@ @@config({flags: ["-w", "a", "-bs-no-bin-annot"]}) +open Belt + module Random = { let self_init = () => () @@ -1109,7 +1111,7 @@ module Object: { let update_player = (player, keys, context) => { let prev_jumping = player.jumping let prev_dir = player.dir and prev_vx = abs_float(player.vel.x) - List.iter(update_player_keys(player, ...), keys) + keys->List.forEach(update_player_keys(player, ...)) let v = player.vel.x *. friction let vel_damped = if abs_float(v) < 0.1 { 0. @@ -1749,16 +1751,12 @@ module Director: { let obj_at_pos = (dir, pos: xy, collids: list): list => switch dir { | Left => - List.filter( - (col: Object.collidable) => - get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x -. 16., - collids, + collids->List.filter((col: Object.collidable) => + get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x -. 16. ) | _ => - List.filter( - (col: Object.collidable) => - get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x +. 16., - collids, + collids->List.filter((col: Object.collidable) => + get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x +. 16. ) } @@ -1894,12 +1892,10 @@ module Director: { /* Run the broad phase object filtering */ let broad_phase = (collid, all_collids, state) => { let obj = get_obj(collid) - List.filter( - c => - in_viewport(state.vpt, obj.pos) || - (is_player(collid) || - out_of_viewport_below(state.vpt, obj.pos.y)), - all_collids, + all_collids->List.filter(c => + in_viewport(state.vpt, obj.pos) || + (is_player(collid) || + out_of_viewport_below(state.vpt, obj.pos.y)) ) } @@ -2007,13 +2003,13 @@ module Director: { let translate_keys = () => { let k = pressed_keys let ctrls = list{(k.left, CLeft), (k.right, CRight), (k.up, CUp), (k.down, CDown)} - List.fold_left((a, x) => + ctrls->List.reduceReverse(list{}, (a, x) => if fst(x) { list{snd(x), ...a} } else { a } - , list{}, ctrls) + ) } /* run_update is used to update all of the collidables at once. Primarily used @@ -2104,8 +2100,8 @@ module Director: { ...state, vpt: Viewport.update(state.vpt, get_obj(player).pos), } - List.iter(obj => ignore(run_update_collid(state, obj, objs)), objs) - List.iter(part => run_update_particle(state, part), parts) + objs->List.forEach(obj => ignore(run_update_collid(state, obj, objs))) + parts->List.forEach(part => run_update_particle(state, part)) Draw.fps(canvas, fps) Draw.hud(canvas, state.score, state.coins) \"@@"( @@ -2625,7 +2621,7 @@ module Main = { let preload = _ => { let root_dir = "sprites/" let imgs = list{"blocks.png", "items.png", "enemies.png", "mario-small.png"} - List.map(img_src => { + imgs->List.map(img_src => { let img_src = root_dir ++ img_src let img = Html.createImg(Dom_html.document) Dom_html.imageElementToJsObj(img)["src"] = img_src @@ -2640,7 +2636,7 @@ module Main = { true, ), ) - }, imgs) + }) } let _ = Dom_html.windowToJsObj(Dom_html.window)["onload"] = _ => { diff --git a/jscomp/test/mock_mt.js b/jscomp/test/mock_mt.js index 0858be78e9..f542db05c8 100644 --- a/jscomp/test/mock_mt.js +++ b/jscomp/test/mock_mt.js @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function from_pair_suites(name, suites) { console.log([ name, "testing" ]); - List.iter(param => { + Belt_List.forEach(suites, param => { let name = param[0]; let fn = param[1](); switch (fn.TAG) { @@ -79,7 +79,7 @@ function from_pair_suites(name, suites) { console.log("failed: " + fn._0); return; } - }, suites); + }); } exports.from_pair_suites = from_pair_suites; diff --git a/jscomp/test/mock_mt.res b/jscomp/test/mock_mt.res index 1c4819957c..83042f8cab 100644 --- a/jscomp/test/mock_mt.res +++ b/jscomp/test/mock_mt.res @@ -13,7 +13,7 @@ type pair_suites = list<(string, unit => eq)> let from_pair_suites = (name: string, suites: pair_suites) => { Js.log((name, "testing")) - List.iter(((name, code)) => + suites->Belt.List.forEach(((name, code)) => switch code() { | Eq(a, b) => Js.log((name, a, "eq?", b)) | Neq(a, b) => Js.log((name, a, "neq?", b)) @@ -26,5 +26,5 @@ let from_pair_suites = (name: string, suites: pair_suites) => { | FailWith(msg) => Js.log("failed: " ++ msg) | Ok(a) => Js.log((name, a, "ok?")) } - , suites) + ) } diff --git a/jscomp/test/module_alias_test.js b/jscomp/test/module_alias_test.js index 8f65a5e4ab..990dc43023 100644 --- a/jscomp/test/module_alias_test.js +++ b/jscomp/test/module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -29,8 +29,8 @@ function eq(loc, x, y) { function f(x) { console.log(x); - console.log(List.length(x)); - return List; + console.log(Belt_List.length(x)); + return Belt_List; } let h = f(/* [] */0); @@ -46,7 +46,7 @@ let a = h.length({ } }); -eq("File \"module_alias_test.res\", line 33, characters 3-10", a, 3); +eq("File \"module_alias_test.res\", line 35, characters 3-10", a, 3); Mt.from_pair_suites("Module_alias_test", suites.contents); diff --git a/jscomp/test/module_alias_test.res b/jscomp/test/module_alias_test.res index 592f582fc8..718adc897a 100644 --- a/jscomp/test/module_alias_test.res +++ b/jscomp/test/module_alias_test.res @@ -1,3 +1,5 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { diff --git a/jscomp/test/mt.res b/jscomp/test/mt.res index 133a2d7fae..73f9da5a1b 100644 --- a/jscomp/test/mt.res +++ b/jscomp/test/mt.res @@ -80,7 +80,7 @@ let close_enough = (~threshold=0.0000001 /* epsilon_float */, a, b) => abs_float let node_from_pair_suites = (name: string, suites: pair_suites) => { Js.log((name, "testing")) - List.iter(((name, code)) => + suites->Belt.List.forEach(((name, code)) => switch code() { | Eq(a, b) => Js.log((name, a, "eq?", b)) | Neq(a, b) => Js.log((name, a, "neq?", b)) @@ -93,7 +93,7 @@ let node_from_pair_suites = (name: string, suites: pair_suites) => { | FailWith(msg) => Js.log("failed: " ++ msg) | Ok(a) => Js.log((name, a, "ok?")) } - , suites) + ) } let handleCode = spec => diff --git a/jscomp/test/nested_module_alias.js b/jscomp/test/nested_module_alias.js index b55b38f628..ec02b53c36 100644 --- a/jscomp/test/nested_module_alias.js +++ b/jscomp/test/nested_module_alias.js @@ -1,12 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function v(x) { return [ - List.length(x), - List.length(x) + Belt_List.length(x), + Belt_List.length(x) ]; } diff --git a/jscomp/test/nested_module_alias.res b/jscomp/test/nested_module_alias.res index 56992831fd..38010d1b57 100644 --- a/jscomp/test/nested_module_alias.res +++ b/jscomp/test/nested_module_alias.res @@ -1,7 +1,7 @@ -module L = List +module L = Belt.List let v = x => { - module H = List + module H = Belt.List module U = L (H.length(x), U.length(x)) } diff --git a/jscomp/test/offset.js b/jscomp/test/offset.js index 1b3e916f43..49483f0586 100644 --- a/jscomp/test/offset.js +++ b/jscomp/test/offset.js @@ -1,1017 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Primitive_string = require("../../lib/js/primitive_string.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_string.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Primitive_string.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || max_elt(l$p) < v$p) && (r$p === "Empty" || v$p < min_elt(r$p))) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq($$String.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let $$Set = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; +let $$Set; let M = { x: 1, diff --git a/jscomp/test/offset.res b/jscomp/test/offset.res index b7753657e1..c6ed1f247b 100644 --- a/jscomp/test/offset.res +++ b/jscomp/test/offset.res @@ -16,7 +16,7 @@ module M = { let x = 0 let x = 1 - module Set = Set.Make(String) + module Set = Belt.Set.String } include M diff --git a/jscomp/test/queue_test.js b/jscomp/test/queue_test.js deleted file mode 100644 index 06778c8fe6..0000000000 --- a/jscomp/test/queue_test.js +++ /dev/null @@ -1,125 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Queue = require("../../lib/js/queue.js"); -let Queue_402 = require("./queue_402.js"); -let Belt_Array = require("../../lib/js/belt_Array.js"); -let Primitive_array = require("../../lib/js/primitive_array.js"); - -function Test(Queue) { - let to_array = q => { - let v = Belt_Array.make(Queue.length(q), 0); - Queue.fold((i, e) => { - Primitive_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; - }; - let queue_1 = x => { - let q = Queue.create(); - Belt_Array.forEach(x, x => Queue.add(x, q)); - return to_array(q); - }; - return { - to_array: to_array, - queue_1: queue_1 - }; -} - -function to_array(q) { - let v = Belt_Array.make(q.length, 0); - Queue.fold((i, e) => { - Primitive_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; -} - -function queue_1(x) { - let q = { - length: 0, - first: "Nil", - last: "Nil" - }; - Belt_Array.forEach(x, x => Queue.add(x, q)); - return to_array(q); -} - -let T1 = { - to_array: to_array, - queue_1: queue_1 -}; - -function to_array$1(q) { - let v = Belt_Array.make(q.length, 0); - Queue_402.fold((i, e) => { - Primitive_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; -} - -function queue_1$1(x) { - let q = { - length: 0, - tail: undefined - }; - Belt_Array.forEach(x, x => Queue_402.add(x, q)); - return to_array$1(q); -} - -let T2 = { - to_array: to_array$1, - queue_1: queue_1$1 -}; - -let suites_0 = [ - "File \"queue_test.res\", line 35, characters 6-13", - param => { - let x = [ - 3, - 4, - 5, - 2 - ]; - return { - TAG: "Eq", - _0: x, - _1: queue_1(x) - }; - } -]; - -let suites_1 = { - hd: [ - "File \"queue_test.res\", line 42, characters 6-13", - param => { - let x = [ - 3, - 4, - 5, - 2 - ]; - return { - TAG: "Eq", - _0: x, - _1: queue_1$1(x) - }; - } - ], - tl: /* [] */0 -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Queue_test", suites); - -exports.Test = Test; -exports.T1 = T1; -exports.T2 = T2; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/queue_test.res b/jscomp/test/queue_test.res deleted file mode 100644 index 9bc7bbc589..0000000000 --- a/jscomp/test/queue_test.res +++ /dev/null @@ -1,51 +0,0 @@ -open Belt - -module Test = (Queue: module type of Queue) => { - let to_array = q => { - let v = Array.make(Queue.length(q), 0) - \"@@"(ignore, Queue.fold((i, e) => { - v[i] = e - i + 1 - }, 0, q)) - v - } - @val("console.log") @variadic external dump: array<'a> => unit = "" - - let queue_1 = x => { - let q = Queue.create() - /* dump [|q|]; */ - x->Array.forEach(x => Queue.add(x, q)) - /* dump [|q|]; */ - to_array(q) - } - - /* - TODO: Note it needs need recursive values support */ - /* let _ = queue_1 [|38|] */ -} - -module T1 = Test(Queue) -module T2 = Test(Queue_402) -open Mt - -let suites = { - open Mt - list{ - ( - __LOC__, - _ => { - let x = [3, 4, 5, 2] - Eq(x, T1.queue_1(x)) - }, - ), - ( - __LOC__, - _ => { - let x = [3, 4, 5, 2] - Eq(x, T2.queue_1(x)) - }, - ), - } -} - -from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/raw_pure_test.js b/jscomp/test/raw_pure_test.js index d25fdd6914..8a2e554ede 100644 --- a/jscomp/test/raw_pure_test.js +++ b/jscomp/test/raw_pure_test.js @@ -5,7 +5,7 @@ // hello 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let x0 = null; @@ -23,7 +23,7 @@ function f(x) { return x; } -let hh = List.length; +let hh = Belt_List.length; exports.x0 = x0; exports.x2 = x2; diff --git a/jscomp/test/raw_pure_test.res b/jscomp/test/raw_pure_test.res index 4dca38755b..7f5617c6a7 100644 --- a/jscomp/test/raw_pure_test.res +++ b/jscomp/test/raw_pure_test.res @@ -22,7 +22,7 @@ let x3 = %raw(`/ghoghos/`) `) let f = %raw("/*hello*/ 0 ") -let hh = List.length +let hh = Belt.List.length let f = x => { ignore( %raw("//eslint-disable diff --git a/jscomp/test/rec_module_opt.js b/jscomp/test/rec_module_opt.js index d867981849..030a741336 100644 --- a/jscomp/test/rec_module_opt.js +++ b/jscomp/test/rec_module_opt.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Set = require("../../lib/js/set.js"); +let Belt_Id = require("../../lib/js/belt_Id.js"); let Caml_module = require("../../lib/js/caml_module.js"); let Primitive_string = require("../../lib/js/primitive_string.js"); @@ -13,13 +13,13 @@ let A = Caml_module.init_mod([ TAG: "Module", _0: [[ "Function", - "compare" + "cmp" ]] }); -let ASet = $$Set.Make(A); +let AComparable = Belt_Id.MakeComparable(A); -function compare(t1, t2) { +function cmp(t1, t2) { if (t1.TAG === "Leaf") { if (t2.TAG === "Leaf") { return Primitive_string.compare(t1._0, t2._0); @@ -29,7 +29,7 @@ function compare(t1, t2) { } else if (t2.TAG === "Leaf") { return -1; } else { - return ASet.compare(t1._0, t2._0); + return AComparable.cmp(t1._0, t2._0); } } @@ -37,10 +37,10 @@ Caml_module.update_mod({ TAG: "Module", _0: [[ "Function", - "compare" + "cmp" ]] }, A, { - compare: compare + cmp: cmp }); let X0 = {}; @@ -102,7 +102,7 @@ Caml_module.update_mod({ let X; exports.A = A; -exports.ASet = ASet; +exports.AComparable = AComparable; exports.X = X; exports.X0 = X0; exports.Y0 = Y0; diff --git a/jscomp/test/rec_module_opt.res b/jscomp/test/rec_module_opt.res index a3e36cdda7..224a66ea6c 100644 --- a/jscomp/test/rec_module_opt.res +++ b/jscomp/test/rec_module_opt.res @@ -10,20 +10,20 @@ }) module rec A: { - type t = Leaf(string) | Node(ASet.t) - let compare: (t, t) => int + type t = Leaf(string) | Node(AComparable.t) + let cmp: (t, t) => int } = { - type t = Leaf(string) | Node(ASet.t) - let compare = (t1, t2) => + type t = Leaf(string) | Node(AComparable.t) + let cmp = (t1, t2) => switch (t1, t2) { | (Leaf(s1), Leaf(s2)) => Pervasives.compare(s1, s2) | (Leaf(_), Node(_)) => 1 | (Node(_), Leaf(_)) => -1 - | (Node(n1), Node(n2)) => ASet.compare(n1, n2) + | (Node(n1), Node(n2)) => Obj.magic(AComparable.cmp)(n1, n2) } let hello = x => x } -and ASet: Set.S with type elt = A.t = Set.Make(A) +and AComparable: Belt.Id.Comparable with type t = A.t = Belt.Id.MakeComparable(A) module rec X: {} = X diff --git a/jscomp/test/rec_module_test.js b/jscomp/test/rec_module_test.js index 2394c231c4..4f263811fc 100644 --- a/jscomp/test/rec_module_test.js +++ b/jscomp/test/rec_module_test.js @@ -2,10 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); let Caml_module = require("../../lib/js/caml_module.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Primitive_string = require("../../lib/js/primitive_string.js"); let A = Caml_module.init_mod([ "rec_module_test.res", @@ -173,1049 +170,6 @@ let Even = {}; let Odd = {}; -let AAA = Caml_module.init_mod([ - "rec_module_test.res", - 69, - 4 -], { - TAG: "Module", - _0: [[ - "Function", - "compare" - ]] -}); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = AAA.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = AAA.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = AAA.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = AAA.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = AAA.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || AAA.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || AAA.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(AAA.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let ASet = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; - -function compare$1(t1, t2) { - if (t1.TAG === "Leaf") { - if (t2.TAG === "Leaf") { - return Primitive_string.compare(t1._0, t2._0); - } else { - return 1; - } - } else if (t2.TAG === "Leaf") { - return -1; - } else { - return compare(t1._0, t2._0); - } -} - -Caml_module.update_mod({ - TAG: "Module", - _0: [[ - "Function", - "compare" - ]] -}, AAA, { - compare: compare$1 -}); - let suites_0 = [ "test1", param => ({ @@ -1280,35 +234,7 @@ let suites_1 = { _1: B.odd(2) }) ], - tl: { - hd: [ - "test6", - param => ({ - TAG: "Eq", - _0: 2, - _1: cardinal(of_list({ - hd: { - TAG: "Leaf", - _0: "a" - }, - tl: { - hd: { - TAG: "Leaf", - _0: "b" - }, - tl: { - hd: { - TAG: "Leaf", - _0: "a" - }, - tl: /* [] */0 - } - } - })) - }) - ], - tl: /* [] */0 - } + tl: /* [] */0 } } } @@ -1328,7 +254,5 @@ exports.AA = AA; exports.BB = BB; exports.Even = Even; exports.Odd = Odd; -exports.AAA = AAA; -exports.ASet = ASet; exports.suites = suites; /* A Not a pure module */ diff --git a/jscomp/test/rec_module_test.res b/jscomp/test/rec_module_test.res index d549ac63a7..a66cc7c017 100644 --- a/jscomp/test/rec_module_test.res +++ b/jscomp/test/rec_module_test.res @@ -63,21 +63,6 @@ and Odd: { type t = Succ(Even.t) } -module rec AAA: { - type t = Leaf(string) | Node(ASet.t) - let compare: (t, t) => int -} = { - type t = Leaf(string) | Node(ASet.t) - let compare = (t1, t2) => - switch (t1, t2) { - | (Leaf(s1), Leaf(s2)) => Pervasives.compare(s1, s2) - | (Leaf(_), Node(_)) => 1 - | (Node(_), Leaf(_)) => -1 - | (Node(n1), Node(n2)) => ASet.compare(n1, n2) - } -} -and ASet: Set.S with type elt = AAA.t = Set.Make(AAA) - let suites = { open Mt list{ @@ -87,7 +72,6 @@ let suites = { ("test4", _ => Eq(true, A.even(2))), ("test4", _ => Eq(true, AA.even(4))), ("test5", _ => Eq(false, B.odd(2))), - ("test6", _ => Eq(2, ASet.cardinal(ASet.of_list(list{Leaf("a"), Leaf("b"), Leaf("a")})))), } } diff --git a/jscomp/test/recursive_records_test.js b/jscomp/test/recursive_records_test.js index 61816cb5d4..f54168a573 100644 --- a/jscomp/test/recursive_records_test.js +++ b/jscomp/test/recursive_records_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -101,11 +101,11 @@ function f3(x) { return rec_cell3; } -eq("File \"recursive_records_test.res\", line 68, characters 4-11", (List.hd(rec_cell3) + List.hd(List.tl(rec_cell3)) | 0) + List.hd(List.tl(List.tl(rec_cell3))) | 0, 9); +eq("File \"recursive_records_test.res\", line 68, characters 4-11", (Belt_List.headExn(rec_cell3) + Belt_List.headExn(Belt_List.tailExn(rec_cell3)) | 0) + Belt_List.headExn(Belt_List.tailExn(Belt_List.tailExn(rec_cell3))) | 0, 9); let rec_cell3$1 = f3(3); -eq("File \"recursive_records_test.res\", line 77, characters 4-11", (List.hd(rec_cell3$1) + List.hd(List.tl(rec_cell3$1)) | 0) + List.hd(List.tl(List.tl(rec_cell3$1))) | 0, 9); +eq("File \"recursive_records_test.res\", line 78, characters 4-11", (Belt_List.headExn(rec_cell3$1) + Belt_List.headExn(Belt_List.tailExn(rec_cell3$1)) | 0) + Belt_List.headExn(Belt_List.tailExn(Belt_List.tailExn(rec_cell3$1))) | 0, 9); Mt.from_pair_suites("recursive_records_test.res", suites.contents); diff --git a/jscomp/test/recursive_records_test.res b/jscomp/test/recursive_records_test.res index e98f5cc7e9..c7aae2b41e 100644 --- a/jscomp/test/recursive_records_test.res +++ b/jscomp/test/recursive_records_test.res @@ -67,7 +67,8 @@ let () = { eq( __LOC__, { - open List + let hd = Belt.List.headExn + let tl = Belt.List.tailExn hd(rec_cell3) + hd(tl(rec_cell3)) + hd(tl(tl(rec_cell3))) }, 9, @@ -76,7 +77,8 @@ let () = { eq( __LOC__, { - open List + let hd = Belt.List.headExn + let tl = Belt.List.tailExn hd(rec_cell3) + hd(tl(rec_cell3)) + hd(tl(tl(rec_cell3))) }, 9, diff --git a/jscomp/test/set_gen.js b/jscomp/test/set_gen.js index d5e26c887a..a0ef9653b8 100644 --- a/jscomp/test/set_gen.js +++ b/jscomp/test/set_gen.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); @@ -549,7 +549,7 @@ function of_sorted_list(l) { } }); }; - return sub(List.length(l), l)[0]; + return sub(Belt_List.length(l), l)[0]; } function of_sorted_array(l) { diff --git a/jscomp/test/set_gen.res b/jscomp/test/set_gen.res index 6d5a4d5481..7665f3291e 100644 --- a/jscomp/test/set_gen.res +++ b/jscomp/test/set_gen.res @@ -451,7 +451,7 @@ let of_sorted_list = l => { } } - fst(sub(List.length(l), l)) + fst(sub(Belt.List.length(l), l)) } let of_sorted_array = l => { diff --git a/jscomp/test/single_module_alias.js b/jscomp/test/single_module_alias.js deleted file mode 100644 index 4b4c50b69f..0000000000 --- a/jscomp/test/single_module_alias.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -let L; - -exports.L = L; -/* No side effect */ diff --git a/jscomp/test/single_module_alias.res b/jscomp/test/single_module_alias.res deleted file mode 100644 index 9792cc27d5..0000000000 --- a/jscomp/test/single_module_alias.res +++ /dev/null @@ -1 +0,0 @@ -module L = List diff --git a/jscomp/test/stack_comp_test.js b/jscomp/test/stack_comp_test.js deleted file mode 100644 index e48789bbee..0000000000 --- a/jscomp/test/stack_comp_test.js +++ /dev/null @@ -1,452 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Mt_global = require("./mt_global.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(f, param) { - Mt_global.collect_eq(test_id, suites, f, param[0], param[1]); -} - -function assert_(loc, v) { - eq(loc, [ - v, - true - ]); -} - -function to_list(s) { - let l = { - contents: /* [] */0 - }; - List.iter(x => { - l.contents = { - hd: x, - tl: l.contents - }; - }, s.c); - return l.contents; -} - -let S = { - Empty: Stack.Empty, - create: Stack.create, - push: Stack.push, - pop: Stack.pop, - top: Stack.top, - clear: Stack.clear, - copy: Stack.copy, - is_empty: Stack.is_empty, - length: Stack.length, - iter: Stack.iter, - fold: Stack.fold, - to_list: to_list -}; - -function does_raise(f, s) { - try { - f(s); - return false; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stack.Empty) { - return true; - } - throw new Error(exn.RE_EXN_ID, { - cause: exn - }); - } -} - -let s = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 39, characters 10-17", to_list(s) === /* [] */0 && s.len === 0); - -Stack.push(1, s); - -assert_("File \"stack_comp_test.res\", line 41, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: /* [] */0 -}) && s.len === 1); - -Stack.push(2, s); - -assert_("File \"stack_comp_test.res\", line 43, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } -}) && s.len === 2); - -Stack.push(3, s); - -assert_("File \"stack_comp_test.res\", line 45, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } -}) && s.len === 3); - -Stack.push(4, s); - -assert_("File \"stack_comp_test.res\", line 47, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -}) && s.len === 4); - -assert_("File \"stack_comp_test.res\", line 48, characters 10-17", Stack.pop(s) === 4); - -assert_("File \"stack_comp_test.res\", line 49, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } -}) && s.len === 3); - -assert_("File \"stack_comp_test.res\", line 50, characters 10-17", Stack.pop(s) === 3); - -assert_("File \"stack_comp_test.res\", line 51, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } -}) && s.len === 2); - -assert_("File \"stack_comp_test.res\", line 52, characters 10-17", Stack.pop(s) === 2); - -assert_("File \"stack_comp_test.res\", line 53, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: /* [] */0 -}) && s.len === 1); - -assert_("File \"stack_comp_test.res\", line 54, characters 10-17", Stack.pop(s) === 1); - -assert_("File \"stack_comp_test.res\", line 55, characters 10-17", to_list(s) === /* [] */0 && s.len === 0); - -assert_("File \"stack_comp_test.res\", line 56, characters 10-17", does_raise(Stack.pop, s)); - -let s$1 = { - c: /* [] */0, - len: 0 -}; - -Stack.push(1, s$1); - -assert_("File \"stack_comp_test.res\", line 62, characters 10-17", Stack.pop(s$1) === 1); - -assert_("File \"stack_comp_test.res\", line 63, characters 10-17", does_raise(Stack.pop, s$1)); - -Stack.push(2, s$1); - -assert_("File \"stack_comp_test.res\", line 65, characters 10-17", Stack.pop(s$1) === 2); - -assert_("File \"stack_comp_test.res\", line 66, characters 10-17", does_raise(Stack.pop, s$1)); - -assert_("File \"stack_comp_test.res\", line 67, characters 10-17", s$1.len === 0); - -let s$2 = { - c: /* [] */0, - len: 0 -}; - -Stack.push(1, s$2); - -assert_("File \"stack_comp_test.res\", line 73, characters 10-17", Stack.top(s$2) === 1); - -Stack.push(2, s$2); - -assert_("File \"stack_comp_test.res\", line 75, characters 10-17", Stack.top(s$2) === 2); - -Stack.push(3, s$2); - -assert_("File \"stack_comp_test.res\", line 77, characters 10-17", Stack.top(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 78, characters 10-17", Stack.top(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 79, characters 10-17", Stack.pop(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 80, characters 10-17", Stack.top(s$2) === 2); - -assert_("File \"stack_comp_test.res\", line 81, characters 10-17", Stack.pop(s$2) === 2); - -assert_("File \"stack_comp_test.res\", line 82, characters 10-17", Stack.top(s$2) === 1); - -assert_("File \"stack_comp_test.res\", line 83, characters 10-17", Stack.pop(s$2) === 1); - -assert_("File \"stack_comp_test.res\", line 84, characters 10-17", does_raise(Stack.top, s$2)); - -assert_("File \"stack_comp_test.res\", line 85, characters 10-17", does_raise(Stack.top, s$2)); - -let s$3 = { - c: /* [] */0, - len: 0 -}; - -for (let i = 1; i <= 10; ++i) { - Stack.push(i, s$3); -} - -Stack.clear(s$3); - -assert_("File \"stack_comp_test.res\", line 94, characters 10-17", s$3.len === 0); - -assert_("File \"stack_comp_test.res\", line 95, characters 10-17", does_raise(Stack.pop, s$3)); - -assert_("File \"stack_comp_test.res\", line 96, characters 10-17", Caml_obj.equal(s$3, { - c: /* [] */0, - len: 0 -})); - -Stack.push(42, s$3); - -assert_("File \"stack_comp_test.res\", line 98, characters 10-17", Stack.pop(s$3) === 42); - -let s1 = { - c: /* [] */0, - len: 0 -}; - -for (let i$1 = 1; i$1 <= 10; ++i$1) { - Stack.push(i$1, s1); -} - -let s2 = Stack.copy(s1); - -assert_("File \"stack_comp_test.res\", line 107, characters 10-17", Caml_obj.equal(to_list(s1), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 108, characters 10-17", Caml_obj.equal(to_list(s2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 109, characters 10-17", s1.len === 10); - -assert_("File \"stack_comp_test.res\", line 110, characters 10-17", s2.len === 10); - -for (let i$2 = 10; i$2 >= 1; --i$2) { - assert_("File \"stack_comp_test.res\", line 112, characters 12-19", Stack.pop(s1) === i$2); -} - -for (let i$3 = 10; i$3 >= 1; --i$3) { - assert_("File \"stack_comp_test.res\", line 115, characters 12-19", Stack.pop(s2) === i$3); -} - -let s$4 = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 121, characters 10-17", s$4.c === /* [] */0); - -for (let i$4 = 1; i$4 <= 10; ++i$4) { - Stack.push(i$4, s$4); - assert_("File \"stack_comp_test.res\", line 124, characters 12-19", s$4.len === i$4); - assert_("File \"stack_comp_test.res\", line 125, characters 12-19", s$4.c !== /* [] */0); -} - -for (let i$5 = 10; i$5 >= 1; --i$5) { - assert_("File \"stack_comp_test.res\", line 128, characters 12-19", s$4.len === i$5); - assert_("File \"stack_comp_test.res\", line 129, characters 12-19", s$4.c !== /* [] */0); - Stack.pop(s$4); -} - -assert_("File \"stack_comp_test.res\", line 132, characters 10-17", s$4.len === 0); - -assert_("File \"stack_comp_test.res\", line 133, characters 10-17", s$4.c === /* [] */0); - -let s$5 = { - c: /* [] */0, - len: 0 -}; - -for (let i$6 = 10; i$6 >= 1; --i$6) { - Stack.push(i$6, s$5); -} - -let i$7 = { - contents: 1 -}; - -List.iter(j => { - assert_("File \"stack_comp_test.res\", line 143, characters 12-19", i$7.contents === j); - i$7.contents = i$7.contents + 1 | 0; -}, s$5.c); - -let s1$1 = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 150, characters 10-17", s1$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 151, characters 10-17", to_list(s1$1) === /* [] */0); - -let s2$1 = Stack.copy(s1$1); - -assert_("File \"stack_comp_test.res\", line 153, characters 10-17", s1$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 154, characters 10-17", to_list(s1$1) === /* [] */0); - -assert_("File \"stack_comp_test.res\", line 155, characters 10-17", s2$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 156, characters 10-17", to_list(s2$1) === /* [] */0); - -let s1$2 = { - c: /* [] */0, - len: 0 -}; - -for (let i$8 = 1; i$8 <= 4; ++i$8) { - Stack.push(i$8, s1$2); -} - -assert_("File \"stack_comp_test.res\", line 165, characters 10-17", s1$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 166, characters 10-17", Caml_obj.equal(to_list(s1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -let s2$2 = Stack.copy(s1$2); - -assert_("File \"stack_comp_test.res\", line 168, characters 10-17", s1$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 169, characters 10-17", Caml_obj.equal(to_list(s1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 170, characters 10-17", s2$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 171, characters 10-17", Caml_obj.equal(to_list(s2$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -Mt.from_pair_suites("Stack_comp_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.assert_ = assert_; -exports.S = S; -exports.does_raise = does_raise; -/* s Not a pure module */ diff --git a/jscomp/test/stack_comp_test.res b/jscomp/test/stack_comp_test.res deleted file mode 100644 index 326af18a38..0000000000 --- a/jscomp/test/stack_comp_test.res +++ /dev/null @@ -1,174 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2015 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the S Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (f, (a, b)) => Mt_global.collect_eq(test_id, suites, f, a, b) -let assert_ = (loc, v) => eq(loc, (v, true)) - -module S = { - include Stack - - let to_list = s => { - let l = ref(list{}) - iter(x => l := list{x, ...l.contents}, s) - l.contents - } /* from bottom to top */ -} - -let does_raise = (f, s) => - try { - ignore((f(s): int)) - false - } catch { - | S.Empty => true - } - -let () = { - let s = S.create() - () - assert_(__LOC__, S.to_list(s) == list{} && S.length(s) == 0) - S.push(1, s) - assert_(__LOC__, S.to_list(s) == list{1} && S.length(s) == 1) - S.push(2, s) - assert_(__LOC__, S.to_list(s) == list{1, 2} && S.length(s) == 2) - S.push(3, s) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3} && S.length(s) == 3) - S.push(4, s) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3, 4} && S.length(s) == 4) - assert_(__LOC__, S.pop(s) == 4) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3} && S.length(s) == 3) - assert_(__LOC__, S.pop(s) == 3) - assert_(__LOC__, S.to_list(s) == list{1, 2} && S.length(s) == 2) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, S.to_list(s) == list{1} && S.length(s) == 1) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, S.to_list(s) == list{} && S.length(s) == 0) - assert_(__LOC__, does_raise(S.pop, s)) -} - -let () = { - let s = S.create() - S.push(1, s) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, does_raise(S.pop, s)) - S.push(2, s) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, does_raise(S.pop, s)) - assert_(__LOC__, S.length(s) == 0) -} - -let () = { - let s = S.create() - S.push(1, s) - assert_(__LOC__, S.top(s) == 1) - S.push(2, s) - assert_(__LOC__, S.top(s) == 2) - S.push(3, s) - assert_(__LOC__, S.top(s) == 3) - assert_(__LOC__, S.top(s) == 3) - assert_(__LOC__, S.pop(s) == 3) - assert_(__LOC__, S.top(s) == 2) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, S.top(s) == 1) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, does_raise(S.top, s)) - assert_(__LOC__, does_raise(S.top, s)) -} - -let () = { - let s = S.create() - for i in 1 to 10 { - S.push(i, s) - } - S.clear(s) - assert_(__LOC__, S.length(s) == 0) - assert_(__LOC__, does_raise(S.pop, s)) - assert_(__LOC__, s == S.create()) - S.push(42, s) - assert_(__LOC__, S.pop(s) == 42) -} - -let () = { - let s1 = S.create() - for i in 1 to 10 { - S.push(i, s1) - } - let s2 = S.copy(s1) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert_(__LOC__, S.to_list(s2) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert_(__LOC__, S.length(s1) == 10) - assert_(__LOC__, S.length(s2) == 10) - for i in 10 downto 1 { - assert_(__LOC__, S.pop(s1) == i) - } - for i in 10 downto 1 { - assert_(__LOC__, S.pop(s2) == i) - } -} - -let () = { - let s = S.create() - assert_(__LOC__, S.is_empty(s)) - for i in 1 to 10 { - S.push(i, s) - assert_(__LOC__, S.length(s) == i) - assert_(__LOC__, !S.is_empty(s)) - } - for i in 10 downto 1 { - assert_(__LOC__, S.length(s) == i) - assert_(__LOC__, !S.is_empty(s)) - ignore((S.pop(s): int)) - } - assert_(__LOC__, S.length(s) == 0) - assert_(__LOC__, S.is_empty(s)) -} - -let () = { - let s = S.create() - for i in 10 downto 1 { - S.push(i, s) - } - let i = ref(1) - S.iter(j => { - assert_(__LOC__, i.contents == j) - incr(i) - }, s) -} - -let () = { - let s1 = S.create() - assert_(__LOC__, S.length(s1) == 0) - assert_(__LOC__, S.to_list(s1) == list{}) - let s2 = S.copy(s1) - assert_(__LOC__, S.length(s1) == 0) - assert_(__LOC__, S.to_list(s1) == list{}) - assert_(__LOC__, S.length(s2) == 0) - assert_(__LOC__, S.to_list(s2) == list{}) -} - -let () = { - let s1 = S.create() - let _s2 = S.create() - for i in 1 to 4 { - S.push(i, s1) - } - assert_(__LOC__, S.length(s1) == 4) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4}) - let s2 = S.copy(s1) - assert_(__LOC__, S.length(s1) == 4) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4}) - assert_(__LOC__, S.length(s2) == 4) - assert_(__LOC__, S.to_list(s2) == list{1, 2, 3, 4}) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/stack_test.js b/jscomp/test/stack_test.js deleted file mode 100644 index 2dc90165f6..0000000000 --- a/jscomp/test/stack_test.js +++ /dev/null @@ -1,58 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); - -function to_list(v) { - let acc = /* [] */0; - while (v.c !== /* [] */0) { - acc = { - hd: Stack.pop(v), - tl: acc - }; - }; - return List.rev(acc); -} - -function v() { - let v$1 = { - c: /* [] */0, - len: 0 - }; - Stack.push(3, v$1); - Stack.push(4, v$1); - Stack.push(1, v$1); - return to_list(v$1); -} - -let suites_0 = [ - "push_test", - param => ({ - TAG: "Eq", - _0: { - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - _1: v() - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Stack_test", suites); - -exports.to_list = to_list; -exports.v = v; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/stack_test.res b/jscomp/test/stack_test.res deleted file mode 100644 index 48cc753c21..0000000000 --- a/jscomp/test/stack_test.res +++ /dev/null @@ -1,21 +0,0 @@ -open Stack - -let to_list = v => { - let acc = ref(list{}) - while \"@@"(not, is_empty(v)) { - acc := list{pop(v), ...acc.contents} - } - List.rev(acc.contents) -} - -let v = () => { - let v = create() - push(3, v) - push(4, v) - push(1, v) - to_list(v) -} - -let suites = list{("push_test", _ => Mt.Eq(list{1, 4, 3}, v()))} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/string_set.js b/jscomp/test/string_set.js index f47a2101a9..a90a39ad52 100644 --- a/jscomp/test/string_set.js +++ b/jscomp/test/string_set.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); let $$String = require("../../lib/js/string.js"); let Set_gen = require("./set_gen.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Primitive_string = require("../../lib/js/primitive_string.js"); @@ -262,7 +262,7 @@ function of_list(l) { let x3 = match$2.hd; if (match$3) { if (match$3.tl) { - return Set_gen.of_sorted_list(List.sort_uniq($$String.compare, l)); + return Set_gen.of_sorted_list(Belt_List.sort(l, $$String.compare)); } else { return add(match$3.hd, add(x3, add(x2, add(x1, Set_gen.singleton(x0))))); } diff --git a/jscomp/test/string_set.res b/jscomp/test/string_set.res index 508ba18359..493e3aabcd 100644 --- a/jscomp/test/string_set.res +++ b/jscomp/test/string_set.res @@ -192,7 +192,7 @@ let of_list = l => | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(compare_elt, l)) + | _ => of_sorted_list(l->Belt.List.sort(compare_elt)) } let of_array = l => l->Belt.Array.reduceReverse(empty, (acc, x) => add(x, acc)) diff --git a/jscomp/test/test_alias.js b/jscomp/test/test_alias.js deleted file mode 100644 index fc4679b407..0000000000 --- a/jscomp/test/test_alias.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -let v = List.length; - -exports.v = v; -/* No side effect */ diff --git a/jscomp/test/test_alias.res b/jscomp/test/test_alias.res deleted file mode 100644 index 4222ad97ec..0000000000 --- a/jscomp/test/test_alias.res +++ /dev/null @@ -1 +0,0 @@ -let v = Test_global_print.V.length diff --git a/jscomp/test/test_ari.js b/jscomp/test/test_ari.js index 8c25d0ec2b..3fd920ab3b 100644 --- a/jscomp/test/test_ari.js +++ b/jscomp/test/test_ari.js @@ -3,7 +3,7 @@ let U = require("U"); let VV = require("VV"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function f(x, y) { return x + y | 0; @@ -42,109 +42,181 @@ function length_aux(_len, _x) { }; } -let length = List.length; +let length = Belt_List.length; -let compare_lengths = List.compare_lengths; +let size = Belt_List.size; -let compare_length_with = List.compare_length_with; +let head = Belt_List.head; -let cons = List.cons; +let headExn = Belt_List.headExn; -let hd = List.hd; +let tail = Belt_List.tail; -let tl = List.tl; +let tailExn = Belt_List.tailExn; -let nth = List.nth; +let add = Belt_List.add; -let nth_opt = List.nth_opt; +let get = Belt_List.get; -let rev = List.rev; +let getExn = Belt_List.getExn; -let init = List.init; +let make = Belt_List.make; -let append = List.append; +let makeByU = Belt_List.makeByU; -let rev_append = List.rev_append; +let makeBy = Belt_List.makeBy; -let concat = List.concat; +let shuffle = Belt_List.shuffle; -let flatten = List.flatten; +let drop = Belt_List.drop; -let iter = List.iter; +let take = Belt_List.take; -let iteri = List.iteri; +let splitAt = Belt_List.splitAt; -let map = List.map; +let concat = Belt_List.concat; -let mapi = List.mapi; +let concatMany = Belt_List.concatMany; -let rev_map = List.rev_map; +let reverseConcat = Belt_List.reverseConcat; -let fold_left = List.fold_left; +let flatten = Belt_List.flatten; -let fold_right = List.fold_right; +let mapU = Belt_List.mapU; -let iter2 = List.iter2; +let map = Belt_List.map; -let map2 = List.map2; +let zip = Belt_List.zip; -let rev_map2 = List.rev_map2; +let zipByU = Belt_List.zipByU; -let fold_left2 = List.fold_left2; +let zipBy = Belt_List.zipBy; -let fold_right2 = List.fold_right2; +let mapWithIndexU = Belt_List.mapWithIndexU; -let for_all = List.for_all; +let mapWithIndex = Belt_List.mapWithIndex; -let exists = List.exists; +let fromArray = Belt_List.fromArray; -let for_all2 = List.for_all2; +let toArray = Belt_List.toArray; -let exists2 = List.exists2; +let reverse = Belt_List.reverse; -let mem = List.mem; +let mapReverseU = Belt_List.mapReverseU; -let memq = List.memq; +let mapReverse = Belt_List.mapReverse; -let find = List.find; +let forEachU = Belt_List.forEachU; -let find_opt = List.find_opt; +let forEach = Belt_List.forEach; -let filter = List.filter; +let forEachWithIndexU = Belt_List.forEachWithIndexU; -let find_all = List.find_all; +let forEachWithIndex = Belt_List.forEachWithIndex; -let partition = List.partition; +let reduceU = Belt_List.reduceU; -let assoc = List.assoc; +let reduce = Belt_List.reduce; -let assoc_opt = List.assoc_opt; +let reduceWithIndexU = Belt_List.reduceWithIndexU; -let assq = List.assq; +let reduceWithIndex = Belt_List.reduceWithIndex; -let assq_opt = List.assq_opt; +let reduceReverseU = Belt_List.reduceReverseU; -let mem_assoc = List.mem_assoc; +let reduceReverse = Belt_List.reduceReverse; -let mem_assq = List.mem_assq; +let mapReverse2U = Belt_List.mapReverse2U; -let remove_assoc = List.remove_assoc; +let mapReverse2 = Belt_List.mapReverse2; -let remove_assq = List.remove_assq; +let forEach2U = Belt_List.forEach2U; -let split = List.split; +let forEach2 = Belt_List.forEach2; -let combine = List.combine; +let reduce2U = Belt_List.reduce2U; -let sort = List.sort; +let reduce2 = Belt_List.reduce2; -let stable_sort = List.stable_sort; +let reduceReverse2U = Belt_List.reduceReverse2U; -let fast_sort = List.fast_sort; +let reduceReverse2 = Belt_List.reduceReverse2; -let sort_uniq = List.sort_uniq; +let everyU = Belt_List.everyU; -let merge = List.merge; +let every = Belt_List.every; + +let someU = Belt_List.someU; + +let some = Belt_List.some; + +let every2U = Belt_List.every2U; + +let every2 = Belt_List.every2; + +let some2U = Belt_List.some2U; + +let some2 = Belt_List.some2; + +let cmpByLength = Belt_List.cmpByLength; + +let cmpU = Belt_List.cmpU; + +let cmp = Belt_List.cmp; + +let eqU = Belt_List.eqU; + +let eq = Belt_List.eq; + +let hasU = Belt_List.hasU; + +let has = Belt_List.has; + +let getByU = Belt_List.getByU; + +let getBy = Belt_List.getBy; + +let keepU = Belt_List.keepU; + +let keep = Belt_List.keep; + +let filter = Belt_List.filter; + +let keepWithIndexU = Belt_List.keepWithIndexU; + +let keepWithIndex = Belt_List.keepWithIndex; + +let filterWithIndex = Belt_List.filterWithIndex; + +let keepMapU = Belt_List.keepMapU; + +let keepMap = Belt_List.keepMap; + +let partitionU = Belt_List.partitionU; + +let partition = Belt_List.partition; + +let unzip = Belt_List.unzip; + +let getAssocU = Belt_List.getAssocU; + +let getAssoc = Belt_List.getAssoc; + +let hasAssocU = Belt_List.hasAssocU; + +let hasAssoc = Belt_List.hasAssoc; + +let removeAssocU = Belt_List.removeAssocU; + +let removeAssoc = Belt_List.removeAssoc; + +let setAssocU = Belt_List.setAssocU; + +let setAssoc = Belt_List.setAssoc; + +let sortU = Belt_List.sortU; + +let sort = Belt_List.sort; exports.f = f; exports.f1 = f1; @@ -155,55 +227,91 @@ exports.ff = ff; exports.fff = fff; exports.length_aux = length_aux; exports.length = length; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.hd = hd; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; +exports.size = size; +exports.head = head; +exports.headExn = headExn; +exports.tail = tail; +exports.tailExn = tailExn; +exports.add = add; +exports.get = get; +exports.getExn = getExn; +exports.make = make; +exports.makeByU = makeByU; +exports.makeBy = makeBy; +exports.shuffle = shuffle; +exports.drop = drop; +exports.take = take; +exports.splitAt = splitAt; exports.concat = concat; +exports.concatMany = concatMany; +exports.reverseConcat = reverseConcat; exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; +exports.mapU = mapU; exports.map = map; -exports.mapi = mapi; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; +exports.zip = zip; +exports.zipByU = zipByU; +exports.zipBy = zipBy; +exports.mapWithIndexU = mapWithIndexU; +exports.mapWithIndex = mapWithIndex; +exports.fromArray = fromArray; +exports.toArray = toArray; +exports.reverse = reverse; +exports.mapReverseU = mapReverseU; +exports.mapReverse = mapReverse; +exports.forEachU = forEachU; +exports.forEach = forEach; +exports.forEachWithIndexU = forEachWithIndexU; +exports.forEachWithIndex = forEachWithIndex; +exports.reduceU = reduceU; +exports.reduce = reduce; +exports.reduceWithIndexU = reduceWithIndexU; +exports.reduceWithIndex = reduceWithIndex; +exports.reduceReverseU = reduceReverseU; +exports.reduceReverse = reduceReverse; +exports.mapReverse2U = mapReverse2U; +exports.mapReverse2 = mapReverse2; +exports.forEach2U = forEach2U; +exports.forEach2 = forEach2; +exports.reduce2U = reduce2U; +exports.reduce2 = reduce2; +exports.reduceReverse2U = reduceReverse2U; +exports.reduceReverse2 = reduceReverse2; +exports.everyU = everyU; +exports.every = every; +exports.someU = someU; +exports.some = some; +exports.every2U = every2U; +exports.every2 = every2; +exports.some2U = some2U; +exports.some2 = some2; +exports.cmpByLength = cmpByLength; +exports.cmpU = cmpU; +exports.cmp = cmp; +exports.eqU = eqU; +exports.eq = eq; +exports.hasU = hasU; +exports.has = has; +exports.getByU = getByU; +exports.getBy = getBy; +exports.keepU = keepU; +exports.keep = keep; exports.filter = filter; -exports.find_all = find_all; +exports.keepWithIndexU = keepWithIndexU; +exports.keepWithIndex = keepWithIndex; +exports.filterWithIndex = filterWithIndex; +exports.keepMapU = keepMapU; +exports.keepMap = keepMap; +exports.partitionU = partitionU; exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; +exports.unzip = unzip; +exports.getAssocU = getAssocU; +exports.getAssoc = getAssoc; +exports.hasAssocU = hasAssocU; +exports.hasAssoc = hasAssoc; +exports.removeAssocU = removeAssocU; +exports.removeAssoc = removeAssoc; +exports.setAssocU = setAssocU; +exports.setAssoc = setAssoc; +exports.sortU = sortU; exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; /* fff Not a pure module */ diff --git a/jscomp/test/test_ari.res b/jscomp/test/test_ari.res index 6fbf8ef541..8d970ef301 100644 --- a/jscomp/test/test_ari.res +++ b/jscomp/test/test_ari.res @@ -31,4 +31,4 @@ let rec length_aux = (len, x) => | list{a, ...l} => length_aux(len + 1, l) } -include List +include Belt.List diff --git a/jscomp/test/test_demo.js b/jscomp/test/test_demo.js index f3100bae74..3e473e9cc1 100644 --- a/jscomp/test/test_demo.js +++ b/jscomp/test/test_demo.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function fib(x) { if (x === 2 || x === 1) { @@ -64,7 +64,7 @@ function v(extra) { let nil = "Nil"; -let len = List.length; +let len = Belt_List.length; exports.fib = fib; exports.nil = nil; diff --git a/jscomp/test/test_demo.res b/jscomp/test/test_demo.res index 2491a9b140..17e9930d5d 100644 --- a/jscomp/test/test_demo.res +++ b/jscomp/test/test_demo.res @@ -26,7 +26,7 @@ let sum = n => { v.contents } -let len = List.length +let len = Belt.List.length let f = (g, x) => { let u = switch g(x) { diff --git a/jscomp/test/test_for_map.js b/jscomp/test/test_for_map.js index 80ea3a60e5..e2e11189ea 100644 --- a/jscomp/test/test_for_map.js +++ b/jscomp/test/test_for_map.js @@ -1,1013 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); -let Primitive_int = require("../../lib/js/primitive_int.js"); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_int.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_int.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let IntMap = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function assertion_test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - find(i$1, m); + Belt_MapInt.get(m, i$1); } } +let IntMap; + exports.IntMap = IntMap; exports.assertion_test = assertion_test; /* No side effect */ diff --git a/jscomp/test/test_for_map.res b/jscomp/test/test_for_map.res index f0c651c806..3af916caf9 100644 --- a/jscomp/test/test_for_map.res +++ b/jscomp/test/test_for_map.res @@ -1,15 +1,12 @@ -module IntMap = Map.Make({ - type t = int - let compare = (x: int, y) => compare(x, y) -}) +module IntMap = Belt.Map.Int let assertion_test = () => { let m = ref(IntMap.empty) let count = 1000000 for i in 0 to count { - m := IntMap.add(i, i, m.contents) + m := m.contents->IntMap.set(i, i) } for i in 0 to count { - ignore(IntMap.find(i, m.contents)) + m.contents->IntMap.get(i)->ignore } } diff --git a/jscomp/test/test_for_map2.js b/jscomp/test/test_for_map2.js index ff20587c02..285ab94576 100644 --- a/jscomp/test/test_for_map2.js +++ b/jscomp/test/test_for_map2.js @@ -1,17 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Int_map = require("./int_map.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function assertion_test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = Int_map.add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - Int_map.find(i$1, m); + Belt_MapInt.get(m, i$1); } } +let Int_map; + +exports.Int_map = Int_map; exports.assertion_test = assertion_test; /* No side effect */ diff --git a/jscomp/test/test_for_map2.res b/jscomp/test/test_for_map2.res index 775b8ea461..88376a438b 100644 --- a/jscomp/test/test_for_map2.res +++ b/jscomp/test/test_for_map2.res @@ -1,10 +1,12 @@ +module Int_map = Belt.Map.Int + let assertion_test = () => { let m = ref(Int_map.empty) let count = 1000000 for i in 0 to count { - m := Int_map.add(i, i, m.contents) + m := m.contents->Int_map.set(i, i) } for i in 0 to count { - ignore(Int_map.find(i, m.contents)) + m.contents->Int_map.get(i)->ignore } } diff --git a/jscomp/test/test_functor_dead_code.js b/jscomp/test/test_functor_dead_code.js index 4e308ce038..ce4c3e5ee1 100644 --- a/jscomp/test/test_functor_dead_code.js +++ b/jscomp/test/test_functor_dead_code.js @@ -1,8 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +let Belt_MapString = require("../../lib/js/belt_MapString.js"); -let v = true; +let v = Belt_MapString.isEmpty(undefined); exports.v = v; -/* No side effect */ +/* v Not a pure module */ diff --git a/jscomp/test/test_functor_dead_code.res b/jscomp/test/test_functor_dead_code.res index c127b6be98..70ccee01c5 100644 --- a/jscomp/test/test_functor_dead_code.res +++ b/jscomp/test/test_functor_dead_code.res @@ -1,7 +1,7 @@ include ( { - module M = Map.Make(String) - let v = M.is_empty(M.empty) + module M = Belt.Map.String + let v = M.isEmpty(M.empty) }: { let v: bool } diff --git a/jscomp/test/test_global_print.js b/jscomp/test/test_global_print.js deleted file mode 100644 index 61ef2a3e26..0000000000 --- a/jscomp/test/test_global_print.js +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -let List = { - u: 3 -}; - -let X = { - List: List -}; - -let Hashtbl; - -let V; - -exports.X = X; -exports.Hashtbl = Hashtbl; -exports.V = V; -/* No side effect */ diff --git a/jscomp/test/test_global_print.res b/jscomp/test/test_global_print.res deleted file mode 100644 index e987681451..0000000000 --- a/jscomp/test/test_global_print.res +++ /dev/null @@ -1,7 +0,0 @@ -module X = { - module List = { - let u = 3 - } -} -module Hashtbl = Hashtbl -module V = List diff --git a/jscomp/test/test_include.js b/jscomp/test/test_include.js index 5c1bb8b227..be35df145d 100644 --- a/jscomp/test/test_include.js +++ b/jscomp/test/test_include.js @@ -1,31 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Test_order = require("./test_order.js"); function Make(U) { - let compare = U.compare; return { - compare: compare, - v: compare + v: U.compare }; } -let X = { - compare: $$String.compare, - v: $$String.compare -}; - let U = { - compare: Test_order.compare, v: Test_order.compare }; let N; -let v = List.length; +let v = Belt_List.length; let N0; @@ -41,114 +32,185 @@ let N5; let N6; -let length = List.length; +let length = Belt_List.length; + +let size = Belt_List.size; + +let head = Belt_List.head; + +let headExn = Belt_List.headExn; + +let tail = Belt_List.tail; + +let tailExn = Belt_List.tailExn; + +let add = Belt_List.add; + +let get = Belt_List.get; + +let getExn = Belt_List.getExn; + +let make = Belt_List.make; + +let makeByU = Belt_List.makeByU; + +let makeBy = Belt_List.makeBy; + +let shuffle = Belt_List.shuffle; + +let drop = Belt_List.drop; + +let take = Belt_List.take; + +let splitAt = Belt_List.splitAt; + +let concat = Belt_List.concat; + +let concatMany = Belt_List.concatMany; + +let reverseConcat = Belt_List.reverseConcat; + +let flatten = Belt_List.flatten; + +let mapU = Belt_List.mapU; + +let map = Belt_List.map; + +let zip = Belt_List.zip; + +let zipByU = Belt_List.zipByU; + +let zipBy = Belt_List.zipBy; + +let mapWithIndexU = Belt_List.mapWithIndexU; + +let mapWithIndex = Belt_List.mapWithIndex; + +let fromArray = Belt_List.fromArray; + +let toArray = Belt_List.toArray; + +let reverse = Belt_List.reverse; + +let mapReverseU = Belt_List.mapReverseU; + +let mapReverse = Belt_List.mapReverse; + +let forEachU = Belt_List.forEachU; + +let forEach = Belt_List.forEach; + +let forEachWithIndexU = Belt_List.forEachWithIndexU; + +let forEachWithIndex = Belt_List.forEachWithIndex; + +let reduceU = Belt_List.reduceU; -let compare_lengths = List.compare_lengths; +let reduce = Belt_List.reduce; -let compare_length_with = List.compare_length_with; +let reduceWithIndexU = Belt_List.reduceWithIndexU; -let cons = List.cons; +let reduceWithIndex = Belt_List.reduceWithIndex; -let hd = List.hd; +let reduceReverseU = Belt_List.reduceReverseU; -let tl = List.tl; +let reduceReverse = Belt_List.reduceReverse; -let nth = List.nth; +let mapReverse2U = Belt_List.mapReverse2U; -let nth_opt = List.nth_opt; +let mapReverse2 = Belt_List.mapReverse2; -let rev = List.rev; +let forEach2U = Belt_List.forEach2U; -let init = List.init; +let forEach2 = Belt_List.forEach2; -let append = List.append; +let reduce2U = Belt_List.reduce2U; -let rev_append = List.rev_append; +let reduce2 = Belt_List.reduce2; -let concat = List.concat; +let reduceReverse2U = Belt_List.reduceReverse2U; -let flatten = List.flatten; +let reduceReverse2 = Belt_List.reduceReverse2; -let iter = List.iter; +let everyU = Belt_List.everyU; -let iteri = List.iteri; +let every = Belt_List.every; -let map = List.map; +let someU = Belt_List.someU; -let mapi = List.mapi; +let some = Belt_List.some; -let rev_map = List.rev_map; +let every2U = Belt_List.every2U; -let fold_left = List.fold_left; +let every2 = Belt_List.every2; -let fold_right = List.fold_right; +let some2U = Belt_List.some2U; -let iter2 = List.iter2; +let some2 = Belt_List.some2; -let map2 = List.map2; +let cmpByLength = Belt_List.cmpByLength; -let rev_map2 = List.rev_map2; +let cmpU = Belt_List.cmpU; -let fold_left2 = List.fold_left2; +let cmp = Belt_List.cmp; -let fold_right2 = List.fold_right2; +let eqU = Belt_List.eqU; -let for_all = List.for_all; +let eq = Belt_List.eq; -let exists = List.exists; +let hasU = Belt_List.hasU; -let for_all2 = List.for_all2; +let has = Belt_List.has; -let exists2 = List.exists2; +let getByU = Belt_List.getByU; -let mem = List.mem; +let getBy = Belt_List.getBy; -let memq = List.memq; +let keepU = Belt_List.keepU; -let find = List.find; +let keep = Belt_List.keep; -let find_opt = List.find_opt; +let filter = Belt_List.filter; -let filter = List.filter; +let keepWithIndexU = Belt_List.keepWithIndexU; -let find_all = List.find_all; +let keepWithIndex = Belt_List.keepWithIndex; -let partition = List.partition; +let filterWithIndex = Belt_List.filterWithIndex; -let assoc = List.assoc; +let keepMapU = Belt_List.keepMapU; -let assoc_opt = List.assoc_opt; +let keepMap = Belt_List.keepMap; -let assq = List.assq; +let partitionU = Belt_List.partitionU; -let assq_opt = List.assq_opt; +let partition = Belt_List.partition; -let mem_assoc = List.mem_assoc; +let unzip = Belt_List.unzip; -let mem_assq = List.mem_assq; +let getAssocU = Belt_List.getAssocU; -let remove_assoc = List.remove_assoc; +let getAssoc = Belt_List.getAssoc; -let remove_assq = List.remove_assq; +let hasAssocU = Belt_List.hasAssocU; -let split = List.split; +let hasAssoc = Belt_List.hasAssoc; -let combine = List.combine; +let removeAssocU = Belt_List.removeAssocU; -let sort = List.sort; +let removeAssoc = Belt_List.removeAssoc; -let stable_sort = List.stable_sort; +let setAssocU = Belt_List.setAssocU; -let fast_sort = List.fast_sort; +let setAssoc = Belt_List.setAssoc; -let sort_uniq = List.sort_uniq; +let sortU = Belt_List.sortU; -let merge = List.merge; +let sort = Belt_List.sort; exports.N = N; exports.v = v; exports.Make = Make; -exports.X = X; exports.U = U; exports.N0 = N0; exports.N1 = N1; @@ -158,55 +220,91 @@ exports.N4 = N4; exports.N5 = N5; exports.N6 = N6; exports.length = length; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.hd = hd; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; +exports.size = size; +exports.head = head; +exports.headExn = headExn; +exports.tail = tail; +exports.tailExn = tailExn; +exports.add = add; +exports.get = get; +exports.getExn = getExn; +exports.make = make; +exports.makeByU = makeByU; +exports.makeBy = makeBy; +exports.shuffle = shuffle; +exports.drop = drop; +exports.take = take; +exports.splitAt = splitAt; exports.concat = concat; +exports.concatMany = concatMany; +exports.reverseConcat = reverseConcat; exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; +exports.mapU = mapU; exports.map = map; -exports.mapi = mapi; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; +exports.zip = zip; +exports.zipByU = zipByU; +exports.zipBy = zipBy; +exports.mapWithIndexU = mapWithIndexU; +exports.mapWithIndex = mapWithIndex; +exports.fromArray = fromArray; +exports.toArray = toArray; +exports.reverse = reverse; +exports.mapReverseU = mapReverseU; +exports.mapReverse = mapReverse; +exports.forEachU = forEachU; +exports.forEach = forEach; +exports.forEachWithIndexU = forEachWithIndexU; +exports.forEachWithIndex = forEachWithIndex; +exports.reduceU = reduceU; +exports.reduce = reduce; +exports.reduceWithIndexU = reduceWithIndexU; +exports.reduceWithIndex = reduceWithIndex; +exports.reduceReverseU = reduceReverseU; +exports.reduceReverse = reduceReverse; +exports.mapReverse2U = mapReverse2U; +exports.mapReverse2 = mapReverse2; +exports.forEach2U = forEach2U; +exports.forEach2 = forEach2; +exports.reduce2U = reduce2U; +exports.reduce2 = reduce2; +exports.reduceReverse2U = reduceReverse2U; +exports.reduceReverse2 = reduceReverse2; +exports.everyU = everyU; +exports.every = every; +exports.someU = someU; +exports.some = some; +exports.every2U = every2U; +exports.every2 = every2; +exports.some2U = some2U; +exports.some2 = some2; +exports.cmpByLength = cmpByLength; +exports.cmpU = cmpU; +exports.cmp = cmp; +exports.eqU = eqU; +exports.eq = eq; +exports.hasU = hasU; +exports.has = has; +exports.getByU = getByU; +exports.getBy = getBy; +exports.keepU = keepU; +exports.keep = keep; exports.filter = filter; -exports.find_all = find_all; +exports.keepWithIndexU = keepWithIndexU; +exports.keepWithIndex = keepWithIndex; +exports.filterWithIndex = filterWithIndex; +exports.keepMapU = keepMapU; +exports.keepMap = keepMap; +exports.partitionU = partitionU; exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; +exports.unzip = unzip; +exports.getAssocU = getAssocU; +exports.getAssoc = getAssoc; +exports.hasAssocU = hasAssocU; +exports.hasAssoc = hasAssoc; +exports.removeAssocU = removeAssocU; +exports.removeAssoc = removeAssoc; +exports.setAssocU = setAssocU; +exports.setAssoc = setAssoc; +exports.sortU = sortU; exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; /* No side effect */ diff --git a/jscomp/test/test_include.res b/jscomp/test/test_include.res index 118142503d..632975fee3 100644 --- a/jscomp/test/test_include.res +++ b/jscomp/test/test_include.res @@ -1,20 +1,18 @@ -/** luckily we have module alias - so global module alias is fine -*/ -include List -module N = List +open Belt + +module N = Belt.List let v = N.length -module Make = (U: Set.OrderedType) => { - include U - let v = compare +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + let v = U.compare } -/* var $$let=$$String; */ -module X = Make(String) module U = Make(Test_order) -/* var X=Make([0,$$let[25]]); */ -include N /* Missing optimization alias to a number could also be removed, especially 0 diff --git a/jscomp/test/test_int_map_find.js b/jscomp/test/test_int_map_find.js index 3d420be338..d6b87b488c 100644 --- a/jscomp/test/test_int_map_find.js +++ b/jscomp/test/test_int_map_find.js @@ -1,144 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let Primitive_int = require("../../lib/js/primitive_int.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_int.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -162,6 +28,6 @@ List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, undefined, (acc, param) => Belt_MapInt.set(acc, param[0], param[1])); /* Not a pure module */ diff --git a/jscomp/test/test_int_map_find.res b/jscomp/test/test_int_map_find.res index ff9a283eb0..8f2da1cb9b 100644 --- a/jscomp/test/test_int_map_find.res +++ b/jscomp/test/test_int_map_find.res @@ -1,22 +1,20 @@ +open Belt + include ( { - module IntMap = Map.Make({ - type t = int - let compare = (x: t, y) => compare(x, y) - }) + module IntMap = Map.Int let empty = IntMap.empty - let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, - ) + let m = List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), + ) => acc->IntMap.set(k, v)) /* external log : 'a -> unit = "" [@@val "console.log"] */ let assert_test = () => - if IntMap.find(10, m) == 'a' { + if m->IntMap.get(10) == Some('a') { Js.log("hi") } else { /* log ('a', "succeed") */ diff --git a/jscomp/test/test_js_ffi.js b/jscomp/test/test_js_ffi.js index 5d16b04b34..b441d700a9 100644 --- a/jscomp/test/test_js_ffi.js +++ b/jscomp/test/test_js_ffi.js @@ -1,17 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$String = require("../../lib/js/string.js"); +let Test_order = require("./test_order.js"); function v(u) { - t($$String); + t(Test_order); } function u(v) { return v; } -let s = $$String; +let s = Test_order; exports.v = v; exports.u = u; diff --git a/jscomp/test/test_js_ffi.res b/jscomp/test/test_js_ffi.res index 80bbbe1565..3717da8b1c 100644 --- a/jscomp/test/test_js_ffi.res +++ b/jscomp/test/test_js_ffi.res @@ -8,12 +8,17 @@ let v = u => { u } -@val("t") external test_f: module(Set.OrderedType) => unit = "?update_dummy" +module type OrderedType = { + type t + let compare: (t, t) => int +} + +@val("t") external test_f: module(OrderedType) => unit = "?update_dummy" -let v = u => test_f(module(String)) +let v = u => test_f(module(Test_order)) -module type X = module type of String +module type X = module type of Test_order let u = (v: module(X)) => v -let s = u(module(String)) +let s = u(module(Test_order)) diff --git a/jscomp/test/test_list.js b/jscomp/test/test_list.js index 772e2f01d1..727128ae2d 100644 --- a/jscomp/test/test_list.js +++ b/jscomp/test/test_list.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); function length_aux(_len, _x) { @@ -1510,7 +1510,7 @@ function sort_uniq(cmp, l) { } } -let u = List.length; +let u = Belt_List.length; let append = Pervasives.$at; diff --git a/jscomp/test/test_list.res b/jscomp/test/test_list.res index c4bfeb3804..915566e571 100644 --- a/jscomp/test/test_list.res +++ b/jscomp/test/test_list.res @@ -13,7 +13,7 @@ /* List operations */ -let u = List.length +let u = Belt.List.length let rec length_aux = (len, x) => switch x { | list{} => len diff --git a/jscomp/test/test_mutliple.js b/jscomp/test/test_mutliple.js deleted file mode 100644 index 404f57bca2..0000000000 --- a/jscomp/test/test_mutliple.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -let f = List.length(/* [] */0); - -exports.f = f; -/* f Not a pure module */ diff --git a/jscomp/test/test_mutliple.res b/jscomp/test/test_mutliple.res deleted file mode 100644 index 6550ffcb49..0000000000 --- a/jscomp/test/test_mutliple.res +++ /dev/null @@ -1 +0,0 @@ -let f = List.length(list{}) diff --git a/jscomp/test/test_non_export.js b/jscomp/test/test_non_export.js index d856702bfe..d5f7e2fcca 100644 --- a/jscomp/test/test_non_export.js +++ b/jscomp/test/test_non_export.js @@ -1,2 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ +'use strict'; + + +function Make(U) { + return U; +} + +exports.Make = Make; +/* No side effect */ diff --git a/jscomp/test/test_non_export.res b/jscomp/test/test_non_export.res index c75fd6f29e..9a920dac82 100644 --- a/jscomp/test/test_non_export.res +++ b/jscomp/test/test_non_export.res @@ -1,20 +1,28 @@ +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + include U +} + include ( { - module V = String + module V = Test_order module U = V - let u = U.get - let v = module(U: Set.OrderedType) + let v = module(U: OrderedType) let pack = h => { - module U = unpack(h: Set.OrderedType) - module V = Set.Make(U) - module(V: Set.S) + module U = unpack(h: OrderedType) + module V = Make(U) + module(V: OrderedType) } let g = pack(v) - let gg = pack(module(String)) - module N = Set.Make(U) - module NN = Set.Make(String) + let gg = pack(module(Test_order)) + module N = Make(U) + module NN = Make(Test_order) }: {} ) diff --git a/jscomp/test/test_pervasive.js b/jscomp/test/test_pervasive.js index ae8875d744..f37d68fd0c 100644 --- a/jscomp/test/test_pervasive.js +++ b/jscomp/test/test_pervasive.js @@ -1,62 +1,98 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Pervasives$1 = { - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, + length: Belt_List.length, + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort, invalid_arg: Pervasives.invalid_arg, failwith: Pervasives.failwith, Exit: Pervasives.Exit, diff --git a/jscomp/test/test_pervasive.res b/jscomp/test/test_pervasive.res index 7463c6d426..f280901a48 100644 --- a/jscomp/test/test_pervasive.res +++ b/jscomp/test/test_pervasive.res @@ -1,5 +1,5 @@ module Pervasives = { - include List + include Belt.List include Pervasives } diff --git a/jscomp/test/test_pervasives2.js b/jscomp/test/test_pervasives2.js deleted file mode 100644 index b53acf108c..0000000000 --- a/jscomp/test/test_pervasives2.js +++ /dev/null @@ -1,118 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); -let Pervasives = require("../../lib/js/pervasives.js"); - -let List$1 = { - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - $at: Pervasives.$at -}; - -let U = { - Empty: Stack.Empty, - create: Stack.create, - push: Stack.push, - pop: Stack.pop, - top: Stack.top, - clear: Stack.clear, - copy: Stack.copy, - is_empty: Stack.is_empty, - length: Stack.length, - iter: Stack.iter, - fold: Stack.fold, - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - $at: Pervasives.$at -}; - -let f = Pervasives.$at; - -let ff = List.length; - -let fff = Pervasives.$at; - -exports.List = List$1; -exports.U = U; -exports.f = f; -exports.ff = ff; -exports.fff = fff; -/* No side effect */ diff --git a/jscomp/test/test_pervasives2.res b/jscomp/test/test_pervasives2.res deleted file mode 100644 index 4163ca8dba..0000000000 --- a/jscomp/test/test_pervasives2.res +++ /dev/null @@ -1,14 +0,0 @@ -module List = { - include List - include Pervasives -} - -module U = { - include Stack - include Pervasives -} - -let f = List.\"@" -let ff = List.length - -let fff = U.\"@" diff --git a/jscomp/test/test_pervasives3.js b/jscomp/test/test_pervasives3.js index 818403f70c..ce6b8766bc 100644 --- a/jscomp/test/test_pervasives3.js +++ b/jscomp/test/test_pervasives3.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Pervasives$1 = { @@ -20,58 +20,94 @@ let Pervasives$1 = { classify_float: Pervasives.classify_float, char_of_int: Pervasives.char_of_int, $at: Pervasives.$at, - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge + length: Belt_List.length, + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort }; let v = Pervasives.$at; diff --git a/jscomp/test/test_pervasives3.res b/jscomp/test/test_pervasives3.res index d9118e4a6c..a56aae6ad5 100644 --- a/jscomp/test/test_pervasives3.res +++ b/jscomp/test/test_pervasives3.res @@ -1,5 +1,5 @@ module Pervasives = { include Pervasives - include List + include Belt.List } let v = Pervasives.\"@" diff --git a/jscomp/test/test_set.js b/jscomp/test/test_set.js index ff3dca7cfa..593ff0ad9f 100644 --- a/jscomp/test/test_set.js +++ b/jscomp/test/test_set.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function Make(Ord) { let height = x => { @@ -681,7 +681,7 @@ function Make(Ord) { } }); }; - return sub(List.length(l), l)[0]; + return sub(Belt_List.length(l), l)[0]; }; let of_list = l => { if (!l) { @@ -706,7 +706,7 @@ function Make(Ord) { let x3 = match$2.hd; if (match$3) { if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); + return of_sorted_list(Belt_List.sort(l, Ord.compare)); } else { return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); } diff --git a/jscomp/test/test_set.res b/jscomp/test/test_set.res index 5d95e32f64..1abeb01034 100644 --- a/jscomp/test/test_set.res +++ b/jscomp/test/test_set.res @@ -501,7 +501,7 @@ module Make = (Ord: OrderedType) => { } } - fst(sub(List.length(l), l)) + fst(sub(Belt.List.length(l), l)) } let of_list = l => @@ -512,7 +512,7 @@ module Make = (Ord: OrderedType) => { | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) + | _ => of_sorted_list(l->Belt.List.sort(Ord.compare)) } } module N = { diff --git a/jscomp/test/test_stack.js b/jscomp/test/test_stack.js deleted file mode 100644 index 4c31d7845d..0000000000 --- a/jscomp/test/test_stack.js +++ /dev/null @@ -1,10 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function v(x) { - return x.c === /* [] */0; -} - -exports.v = v; -/* No side effect */ diff --git a/jscomp/test/test_stack.res b/jscomp/test/test_stack.res deleted file mode 100644 index 7e2db0e097..0000000000 --- a/jscomp/test/test_stack.res +++ /dev/null @@ -1 +0,0 @@ -let v = x => Stack.is_empty(x) diff --git a/jscomp/test/test_string_map.js b/jscomp/test/test_string_map.js index a8d5de3502..4c5940c39e 100644 --- a/jscomp/test/test_string_map.js +++ b/jscomp/test/test_string_map.js @@ -1,160 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Primitive_string = require("../../lib/js/primitive_string.js"); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} +let Belt_MapString = require("../../lib/js/belt_MapString.js"); function timing(label, f) { console.time(label); @@ -164,16 +11,16 @@ function timing(label, f) { function assertion_test() { let m = { - contents: "Empty" + contents: undefined }; timing("building", () => { for (let i = 0; i <= 1000000; ++i) { - m.contents = add(i.toString(), i.toString(), m.contents); + m.contents = Belt_MapString.set(m.contents, i.toString(), i.toString()); } }); timing("querying", () => { for (let i = 0; i <= 1000000; ++i) { - find(i.toString(), m.contents); + Belt_MapString.get(m.contents, i.toString()); } }); } diff --git a/jscomp/test/test_string_map.res b/jscomp/test/test_string_map.res index f0474cd8fb..7bc1a0cb29 100644 --- a/jscomp/test/test_string_map.res +++ b/jscomp/test/test_string_map.res @@ -1,9 +1,6 @@ include ( { - module StringMap = Map.Make({ - type t = string - let compare = (x: string, y) => compare(x, y) - }) + module StringMap = Belt.Map.String @val("console.time") external time: string => unit = "" @val("console.timeEnd") external timeEnd: string => unit = "" @@ -18,12 +15,12 @@ include ( let count = 1000000 \"@@"(timing("building", ...), _ => for i in 0 to count { - m := StringMap.add(Js.Int.toString(i), Js.Int.toString(i), m.contents) + m := m.contents->StringMap.set(Js.Int.toString(i), Js.Int.toString(i)) } ) \"@@"(timing("querying", ...), _ => for i in 0 to count { - ignore(StringMap.find(Js.Int.toString(i), m.contents)) + m.contents->StringMap.get(Js.Int.toString(i))->ignore } ) } diff --git a/jscomp/test/ticker.js b/jscomp/test/ticker.js index ac49616554..34034c9843 100644 --- a/jscomp/test/ticker.js +++ b/jscomp/test/ticker.js @@ -1,13 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Float = require("../../lib/js/belt_Float.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Belt_Option = require("../../lib/js/belt_Option.js"); let Caml_option = require("../../lib/js/caml_option.js"); let Primitive_int = require("../../lib/js/primitive_int.js"); +let Belt_MapString = require("../../lib/js/belt_MapString.js"); function split(delim, s) { let len = s.length; @@ -71,1015 +71,21 @@ function string_of_rank(x) { } function find_ticker_by_name(all_tickers, ticker) { - return List.find(param => param.ticker_name === ticker, all_tickers); + return Belt_Option.getExn(Belt_List.getBy(all_tickers, param => param.ticker_name === ticker)); } function print_all_composite(all_tickers) { - List.iter(x => { + Belt_List.forEach(all_tickers, x => { let tmp = x.type_; if (typeof tmp !== "object") { return; } console.log(x.ticker_name); - }, all_tickers); -} - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } }); } -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split$1(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split$1(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split$1(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split$1(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split$1(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split$1(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split$1(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml_obj.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let Ticker_map = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split$1, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; - function compute_update_sequences(all_tickers) { - List.fold_left((counter, ticker) => { + Belt_List.reduceReverse(all_tickers, 0, (counter, ticker) => { let loop = (counter, ticker) => { let rank = ticker.rank; if (typeof rank === "object") { @@ -1109,14 +115,14 @@ function compute_update_sequences(all_tickers) { return counter$4; }; return loop(counter, ticker); - }, 0, all_tickers); - let map = List.fold_left((map, ticker) => { + }); + let map = Belt_List.reduceReverse(Belt_List.reverse(all_tickers), undefined, (map, ticker) => { let tmp = ticker.type_; if (typeof tmp !== "object") { - return add(ticker.ticker_name, { + return Belt_MapString.set(map, ticker.ticker_name, { hd: ticker, tl: /* [] */0 - }, map); + }); } let loop = (_up, _map, _ticker) => { while (true) { @@ -1126,8 +132,8 @@ function compute_update_sequences(all_tickers) { let type_ = ticker.type_; let ticker_name = ticker.ticker_name; if (typeof type_ !== "object") { - let l = find(ticker_name, map); - return add(ticker_name, Pervasives.$at(up, l), map); + let l = Belt_MapString.getExn(map, ticker_name); + return Belt_MapString.set(map, ticker_name, Pervasives.$at(up, l)); } let match = type_._0; let map$1 = loop({ @@ -1144,9 +150,9 @@ function compute_update_sequences(all_tickers) { }; }; return loop(/* [] */0, map, ticker); - }, "Empty", List.rev(all_tickers)); - return fold((k, l, map) => { - let l$1 = List.sort_uniq((lhs, rhs) => { + }); + return Belt_MapString.reduce(map, map, (map, k, l) => { + let l$1 = Belt_List.sort(l, (lhs, rhs) => { let x = lhs.rank; if (typeof x !== "object") { if (x === "Uninitialized") { @@ -1183,14 +189,14 @@ function compute_update_sequences(all_tickers) { } }); } - }, l); - return add(k, l$1, map); - }, map, map); + }); + return Belt_MapString.set(map, k, l$1); + }); } function process_quote(ticker_map, new_ticker, new_value) { - let update_sequence = find(new_ticker, ticker_map); - List.iter(ticker => { + let update_sequence = Belt_MapString.getExn(ticker_map, new_ticker); + Belt_List.forEach(update_sequence, ticker => { let match = ticker.type_; if (typeof match !== "object") { if (ticker.ticker_name === new_ticker) { @@ -1211,7 +217,7 @@ function process_quote(ticker_map, new_ticker, new_value) { match$1.op === "PLUS" ? match$2 + match$3 : match$2 - match$3 ) : undefined; ticker.value = value; - }, update_sequence); + }); } function process_input_line(ticker_map, all_tickers, line) { @@ -1421,6 +427,8 @@ function loop(_lines, _param) { }; } +let Ticker_map; + let lines = { hd: "R|MSFT|S", tl: { diff --git a/jscomp/test/ticker.res b/jscomp/test/ticker.res index c98fabfb03..8692cade82 100644 --- a/jscomp/test/ticker.res +++ b/jscomp/test/ticker.res @@ -1,3 +1,5 @@ +open Belt + /** General purpose utility functions */ module Util = { @@ -69,9 +71,10 @@ let string_of_rank = x => } let find_ticker_by_name = (all_tickers, ticker) => - List.find(({ticker_name, _}) => ticker_name == ticker, all_tickers) + all_tickers->List.getBy(({ticker_name, _}) => ticker_name == ticker)->Option.getExn -let print_all_composite = all_tickers => List.iter(x => +let print_all_composite = all_tickers => + all_tickers->List.forEach(x => switch x { | {type_: Market, _} => () | {type_: Binary_op(_), ticker_name, value} => @@ -80,12 +83,9 @@ let print_all_composite = all_tickers => List.iter(x => | None => Js.log(ticker_name) } } - , all_tickers) + ) -module Ticker_map = Map.Make({ - type t = string - let compare = Pervasives.compare -}) +module Ticker_map = Map.String /** For each market tickers, this function will compute the associated list of tickers value to be updated @@ -102,72 +102,77 @@ module Ticker_map = Map.Make({ let compute_update_sequences = all_tickers => { /* Ranking */ - \"@@"(ignore, List.fold_left((counter, ticker) => { - let rec loop = (counter, {rank, _} as ticker) => - switch rank { - | Ranked(_) => counter - | Visited => counter - | Uninitialized => - ticker.rank = Visited - switch ticker.type_ { - | Market => - let counter = counter + 1 - ticker.rank = Ranked(counter) - counter - | Binary_op({lhs, rhs, _}) => - let counter = loop(counter, lhs) - let counter = loop(counter, rhs) - let counter = counter + 1 - ticker.rank = Ranked(counter) - counter - } + all_tickers + ->List.reduceReverse(0, (counter, ticker) => { + let rec loop = (counter, {rank, _} as ticker) => + switch rank { + | Ranked(_) => counter + | Visited => counter + | Uninitialized => + ticker.rank = Visited + switch ticker.type_ { + | Market => + let counter = counter + 1 + ticker.rank = Ranked(counter) + counter + | Binary_op({lhs, rhs, _}) => + let counter = loop(counter, lhs) + let counter = loop(counter, rhs) + let counter = counter + 1 + ticker.rank = Ranked(counter) + counter } + } - loop(counter, ticker) - }, 0, all_tickers)) + loop(counter, ticker) + }) + ->ignore /* collect all dependencies of market tickers */ - let map = List.fold_left((map, {ticker_name, type_, _} as ticker) => - switch type_ { - | Market => Ticker_map.add(ticker_name, list{ticker}, map) - | _ => - let rec loop = (up, map, {ticker_name, type_} as ticker) => - switch type_ { - | Market => - let l = Ticker_map.find(ticker_name, map) - Ticker_map.add(ticker_name, \"@"(up, l), map) - | Binary_op({lhs, rhs, _}) => - let map = loop(list{ticker, ...up}, map, lhs) - loop(list{ticker, ...up}, map, rhs) - } + let map = + all_tickers + ->List.reverse + ->List.reduceReverse(Ticker_map.empty, (map, {ticker_name, type_, _} as ticker) => + switch type_ { + | Market => map->Ticker_map.set(ticker_name, list{ticker}) + | _ => + let rec loop = (up, map, {ticker_name, type_} as ticker) => + switch type_ { + | Market => + let l = map->Ticker_map.getExn(ticker_name) + map->Ticker_map.set(ticker_name, \"@"(up, l)) + | Binary_op({lhs, rhs, _}) => + let map = loop(list{ticker, ...up}, map, lhs) + loop(list{ticker, ...up}, map, rhs) + } - loop(list{}, map, ticker) - } - , Ticker_map.empty, List.rev(all_tickers)) + loop(list{}, map, ticker) + } + ) /* `List.rev is needed to process the node in the order they were processed TODO: this code should be more robust */ /* order dependencies based on rank */ - Ticker_map.fold((k, l, map) => { - let l = List.sort_uniq((lhs, rhs) => + map->Ticker_map.reduce(map, (map, k, l) => { + let l = l->List.sort((lhs, rhs) => switch (lhs, rhs) { | ({rank: Ranked(x)}, {rank: Ranked(y)}) => Pervasives.compare(x, y) | (_, _) => failwith("All nodes should be ranked") } - , l) - Ticker_map.add(k, l, map) - }, map, map) + ) + map->Ticker_map.set(k, l) + }) } /** Process a new quote for a market ticker */ let process_quote = (ticker_map, new_ticker, new_value) => { - let update_sequence = Ticker_map.find(new_ticker, ticker_map) + let update_sequence = ticker_map->Ticker_map.getExn(new_ticker) - List.iter(ticker => + update_sequence->List.forEach(ticker => switch ticker { | {type_: Market, ticker_name, _} if ticker_name == new_ticker => ticker.value = Some(new_value) @@ -187,7 +192,7 @@ let process_quote = (ticker_map, new_ticker, new_value) => { } ticker.value = value } - , update_sequence) + ) } let process_input_line = (ticker_map, all_tickers, line) => { @@ -222,7 +227,7 @@ let process_input_line = (ticker_map, all_tickers, line) => { | Some(ticker_map) => ticker_map | None => compute_update_sequences(all_tickers) } - let value = value->Belt.Float.fromString->Belt.Option.getExn + let value = value->Float.fromString->Option.getExn process_quote(ticker_map, ticker_name, value) (all_tickers, Some(ticker_map)) | _ => failwith("Invalid input line") diff --git a/jscomp/test/topsort_test.js b/jscomp/test/topsort_test.js index 7602da1f08..5487ddae0c 100644 --- a/jscomp/test/topsort_test.js +++ b/jscomp/test/topsort_test.js @@ -1,13 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Belt_SetString = require("../../lib/js/belt_SetString.js"); let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Primitive_string = require("../../lib/js/primitive_string.js"); let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); let graph = { @@ -61,7 +59,7 @@ let graph = { }; function nexts(x, g) { - return List.fold_left((acc, param) => { + return Belt_List.reduce(g, /* [] */0, (acc, param) => { if (param[0] === x) { return { hd: param[1], @@ -70,7 +68,7 @@ function nexts(x, g) { } else { return acc; } - }, /* [] */0, g); + }); } function dfs1(_nodes, graph, _visited) { @@ -78,11 +76,11 @@ function dfs1(_nodes, graph, _visited) { let visited = _visited; let nodes = _nodes; if (!nodes) { - return List.rev(visited); + return Belt_List.reverse(visited); } let xs = nodes.tl; let x = nodes.hd; - if (List.mem(x, visited)) { + if (Belt_List.has(visited, x, (prim0, prim1) => prim0 === prim1)) { _nodes = xs; continue; } @@ -126,7 +124,7 @@ if (!Caml_obj.equal(dfs1({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 35, + 38, 2 ] } @@ -165,7 +163,7 @@ if (!Caml_obj.equal(dfs1({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 38, + 41, 2 ] } @@ -182,7 +180,7 @@ function dfs2(nodes, graph, visited) { } let xs = nodes.tl; let x = nodes.hd; - if (List.mem(x, visited)) { + if (Belt_List.has(visited, x, (prim0, prim1) => prim0 === prim1)) { _nodes = xs; continue; } @@ -194,7 +192,7 @@ function dfs2(nodes, graph, visited) { continue; }; }; - return List.rev(aux(nodes, graph, visited)); + return Belt_List.reverse(aux(nodes, graph, visited)); } if (!Caml_obj.equal(dfs2({ @@ -227,7 +225,7 @@ if (!Caml_obj.equal(dfs2({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 57, + 60, 2 ] } @@ -264,7 +262,7 @@ if (!Caml_obj.equal(dfs2({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 58, + 61, 2 ] } @@ -276,17 +274,17 @@ function dfs3(nodes, graph) { contents: /* [] */0 }; let aux = (node, graph) => { - if (!List.mem(node, visited.contents)) { + if (!Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { visited.contents = { hd: node, tl: visited.contents }; - return List.iter(x => aux(x, graph), nexts(node, graph)); + return Belt_List.forEach(nexts(node, graph), x => aux(x, graph)); } }; - List.iter(node => aux(node, graph), nodes); - return List.rev(visited.contents); + Belt_List.forEach(nodes, node => aux(node, graph)); + return Belt_List.reverse(visited.contents); } if (!Caml_obj.equal(dfs3({ @@ -319,7 +317,7 @@ if (!Caml_obj.equal(dfs3({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 74, + 77, 2 ] } @@ -356,7 +354,7 @@ if (!Caml_obj.equal(dfs3({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 75, + 78, 2 ] } @@ -406,17 +404,17 @@ function unsafe_topsort(graph) { contents: /* [] */0 }; let sort_node = node => { - if (List.mem(node, visited.contents)) { + if (Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { return; } let nodes = nexts(node, graph); - List.iter(sort_node, nodes); + Belt_List.forEach(nodes, sort_node); visited.contents = { hd: node, tl: visited.contents }; }; - List.iter(param => sort_node(param[0]), graph); + Belt_List.forEach(graph, param => sort_node(param[0])); return visited.contents; } @@ -444,1020 +442,13 @@ if (!Caml_obj.equal(unsafe_topsort(grwork), { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 112, + 115, 9 ] } }); } -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Primitive_string.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Primitive_string.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Primitive_string.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Primitive_string.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Primitive_string.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || max_elt(l$p) < v$p) && (r$p === "Empty" || v$p < min_elt(r$p))) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq($$String.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let String_set = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; - let Cycle = /* @__PURE__ */Caml_exceptions.create("Topsort_test.Cycle"); function pathsort(graph) { @@ -1465,13 +456,13 @@ function pathsort(graph) { contents: /* [] */0 }; let empty_path = [ - "Empty", + undefined, /* [] */0 ]; let $plus$great = (node, param) => { let stack = param[1]; let set = param[0]; - if (mem(node, set)) { + if (Belt_SetString.has(set, node)) { throw new Error(Cycle, { cause: { RE_EXN_ID: Cycle, @@ -1483,16 +474,16 @@ function pathsort(graph) { }); } return [ - add(node, set), + Belt_SetString.add(set, node), { hd: node, tl: stack } ]; }; - let sort_nodes = (path, nodes) => List.iter(node => sort_node(path, node), nodes); + let sort_nodes = (path, nodes) => Belt_List.forEach(nodes, node => sort_node(path, node)); let sort_node = (path, node) => { - if (!List.mem(node, visited.contents)) { + if (!Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { sort_nodes($plus$great(node, path), nexts(node, graph)); visited.contents = { hd: node, @@ -1502,7 +493,7 @@ function pathsort(graph) { } }; - List.iter(param => sort_node(empty_path, param[0]), graph); + Belt_List.forEach(graph, param => sort_node(empty_path, param[0])); return visited.contents; } @@ -1530,7 +521,7 @@ if (!Caml_obj.equal(pathsort(grwork), { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 144, + 147, 9 ] } @@ -1550,7 +541,7 @@ try { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 148, + 151, 2 ] } @@ -1588,7 +579,7 @@ try { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 151, + 154, 7 ] } @@ -1597,6 +588,8 @@ try { } +let String_set; + exports.graph = graph; exports.nexts = nexts; exports.dfs1 = dfs1; diff --git a/jscomp/test/topsort_test.res b/jscomp/test/topsort_test.res index c664998eac..6877d510d7 100644 --- a/jscomp/test/topsort_test.res +++ b/jscomp/test/topsort_test.res @@ -1,3 +1,5 @@ +open Belt + type graph = list<(string, string)> let graph: graph = list{ @@ -11,19 +13,20 @@ let graph: graph = list{ ("e", "g"), } -let nexts = (x: string, g: graph): list => List.fold_left((acc, (a, b)) => +let nexts = (x: string, g: graph): list => + g->List.reduce(list{}, (acc, (a, b)) => if a == x { list{b, ...acc} } else { acc } - , list{}, g) + ) let rec dfs1 = (nodes, graph, visited) => switch nodes { - | list{} => List.rev(visited) + | list{} => List.reverse(visited) | list{x, ...xs} => - if List.mem(x, visited) { + if visited->List.has(x, \"==") { dfs1(xs, graph, visited) } else { Js.log(x) @@ -43,13 +46,13 @@ let rec dfs2 = (nodes, graph, visited) => { switch nodes { | list{} => visited | list{x, ...xs} => - if List.mem(x, visited) { + if visited->List.has(x, \"==") { aux(xs, graph, visited) } else { aux(xs, graph, aux(nexts(x, graph), graph, list{x, ...visited})) } } - \"@@"(List.rev, aux(nodes, graph, visited)) + aux(nodes, graph, visited)->List.reverse } let () = { @@ -61,12 +64,12 @@ let () = { let dfs3 = (nodes, graph) => { let visited = ref(list{}) let rec aux = (node, graph) => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { visited := list{node, ...visited.contents} - List.iter(x => aux(x, graph), nexts(node, graph)) + nexts(node, graph)->List.forEach(x => aux(x, graph)) } - List.iter(node => aux(node, graph), nodes) - List.rev(visited.contents) + nodes->List.forEach(node => aux(node, graph)) + visited.contents->List.reverse } let () = { @@ -90,9 +93,9 @@ let grwork = list{ let unsafe_topsort = graph => { let visited = ref(list{}) - let rec sort_nodes = nodes => List.iter(node => sort_node(node), nodes) + let rec sort_nodes = nodes => nodes->List.forEach(node => sort_node(node)) and sort_node = node => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { /* This check does not prevent cycle , but it is still necessary? yes! since a node can have multiple parents @@ -105,30 +108,30 @@ let unsafe_topsort = graph => { */ visited := list{node, ...visited.contents} } - List.iter(((x, _)) => sort_node(x), graph) + graph->List.forEach(((x, _)) => sort_node(x)) visited.contents } let () = assert(unsafe_topsort(grwork) == list{"wake", "shower", "dress", "eat", "washup", "go"}) -module String_set = Set.Make(String) +module String_set = Belt.Set.String exception Cycle(list) let pathsort = graph => { let visited = ref(list{}) let empty_path = (String_set.empty, list{}) let \"+>" = (node, (set, stack)) => - if String_set.mem(node, set) { + if String_set.has(set, node) { raise(Cycle(list{node, ...stack})) } else { - (String_set.add(node, set), list{node, ...stack}) + (String_set.add(set, node), list{node, ...stack}) } /* let check node (set,stack) = if String_set.mem node set then raise (Cycle (node::stack)) in */ - let rec sort_nodes = (path, nodes) => List.iter(node => sort_node(path, node), nodes) + let rec sort_nodes = (path, nodes) => nodes->List.forEach(node => sort_node(path, node)) and sort_node = (path, node) => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { /* check node path ; */ sort_nodes(\"+>"(node, path), nexts(node, graph)) /* different from dfs, recorded after its @@ -137,14 +140,14 @@ let pathsort = graph => { */ visited := list{node, ...visited.contents} } - List.iter(((x, _)) => sort_node(empty_path, x), graph) + graph->List.forEach(((x, _)) => sort_node(empty_path, x)) visited.contents } let () = assert(pathsort(grwork) == list{"wake", "shower", "dress", "eat", "washup", "go"}) let () = try { - \"@@"(ignore, pathsort(list{("go", "eat"), ...grwork})) + pathsort(list{("go", "eat"), ...grwork})->ignore assert(false) } catch { | Cycle(list{"go", "washup", "eat", "go"}) => () diff --git a/jscomp/test/webpack_config.js b/jscomp/test/webpack_config.js index dacb56068a..08fe58defc 100644 --- a/jscomp/test/webpack_config.js +++ b/jscomp/test/webpack_config.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let List$1 = require("List"); -let List$2 = require("reactV"); -let List$3 = require("reactX"); +let List = require("List"); +let List$1 = require("reactV"); +let List$2 = require("reactX"); let Local = require("./local"); +let Belt_List = require("../../lib/js/belt_List.js"); let WebpackConfigJs = require("../../../webpack.config.js"); let WebpackMiddlewareConfigJs = require("../../../webpack.middleware.config.js"); @@ -40,23 +40,23 @@ let B = {}; function f() { return [ prim => { - List$3.ff(); + List$2.ff(); }, prim => { - List$3.ff2(); + List$2.ff2(); }, prim => { - List$2.ff(); + List$1.ff(); }, prim => { - List$2.ff2(); + List$1.ff2(); } ]; } -List$1.xx(); +List.xx(); -List.length({ +Belt_List.length({ hd: 1, tl: { hd: 2, @@ -64,7 +64,7 @@ List.length({ } }); -List.length(/* [] */0); +Belt_List.length(/* [] */0); function ff(prim) { return Local.ff(); diff --git a/jscomp/test/webpack_config.res b/jscomp/test/webpack_config.res index 96f6ede97a..a013d1456e 100644 --- a/jscomp/test/webpack_config.res +++ b/jscomp/test/webpack_config.res @@ -1,3 +1,5 @@ +open Belt + module type Config = { let configx: Js.Json.t } diff --git a/lib/es6/complex.js b/lib/es6/complex.js deleted file mode 100644 index 9285c41e45..0000000000 --- a/lib/es6/complex.js +++ /dev/null @@ -1,176 +0,0 @@ - - - -let one = { - re: 1.0, - im: 0.0 -}; - -function add(x, y) { - return { - re: x.re + y.re, - im: x.im + y.im - }; -} - -function sub(x, y) { - return { - re: x.re - y.re, - im: x.im - y.im - }; -} - -function neg(x) { - return { - re: - x.re, - im: - x.im - }; -} - -function conj(x) { - return { - re: x.re, - im: - x.im - }; -} - -function mul(x, y) { - return { - re: x.re * y.re - x.im * y.im, - im: x.re * y.im + x.im * y.re - }; -} - -function div(x, y) { - if (Math.abs(y.re) >= Math.abs(y.im)) { - let r = y.im / y.re; - let d = y.re + r * y.im; - return { - re: (x.re + r * x.im) / d, - im: (x.im - r * x.re) / d - }; - } - let r$1 = y.re / y.im; - let d$1 = y.im + r$1 * y.re; - return { - re: (r$1 * x.re + x.im) / d$1, - im: (r$1 * x.im - x.re) / d$1 - }; -} - -function inv(x) { - return div(one, x); -} - -function norm2(x) { - return x.re * x.re + x.im * x.im; -} - -function norm(x) { - let r = Math.abs(x.re); - let i = Math.abs(x.im); - if (r === 0.0) { - return i; - } - if (i === 0.0) { - return r; - } - if (r >= i) { - let q = i / r; - return r * Math.sqrt(1.0 + q * q); - } - let q$1 = r / i; - return i * Math.sqrt(1.0 + q$1 * q$1); -} - -function arg(x) { - return Math.atan2(x.im, x.re); -} - -function polar(n, a) { - return { - re: Math.cos(a) * n, - im: Math.sin(a) * n - }; -} - -function sqrt(x) { - if (x.re === 0.0 && x.im === 0.0) { - return { - re: 0.0, - im: 0.0 - }; - } - let r = Math.abs(x.re); - let i = Math.abs(x.im); - let w; - if (r >= i) { - let q = i / r; - w = Math.sqrt(r) * Math.sqrt(0.5 * (1.0 + Math.sqrt(1.0 + q * q))); - } else { - let q$1 = r / i; - w = Math.sqrt(i) * Math.sqrt(0.5 * (q$1 + Math.sqrt(1.0 + q$1 * q$1))); - } - if (x.re >= 0.0) { - return { - re: w, - im: 0.5 * x.im / w - }; - } else { - return { - re: 0.5 * i / w, - im: x.im >= 0.0 ? w : - w - }; - } -} - -function exp(x) { - let e = Math.exp(x.re); - return { - re: e * Math.cos(x.im), - im: e * Math.sin(x.im) - }; -} - -function log(x) { - return { - re: Math.log(norm(x)), - im: Math.atan2(x.im, x.re) - }; -} - -function pow(x, y) { - return exp(mul(y, log(x))); -} - -let zero = { - re: 0.0, - im: 0.0 -}; - -let i = { - re: 0.0, - im: 1.0 -}; - -export { - zero, - one, - i, - neg, - conj, - add, - sub, - mul, - inv, - div, - sqrt, - norm2, - norm, - arg, - polar, - exp, - log, - pow, -} -/* No side effect */ diff --git a/lib/es6/list.js b/lib/es6/list.js deleted file mode 100644 index 68007f2a5a..0000000000 --- a/lib/es6/list.js +++ /dev/null @@ -1,1735 +0,0 @@ - - -import * as Pervasives from "./pervasives.js"; -import * as Caml_option from "./caml_option.js"; - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "hd" - } - }); -} - -function tl(param) { - if (param) { - return param.tl; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "tl" - } - }); -} - -function nth(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "nth" - } - }); - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - if (l2$1) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - } - if (!l2) { - return; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - } - if (!l2) { - return true; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - } - if (!l2) { - return false; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function memq(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function mem_assq(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "list.res", - 420, - 11 - ] - } - }); - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -export { - length, - compare_lengths, - compare_length_with, - cons, - hd, - tl, - nth, - nth_opt, - rev, - init, - append, - rev_append, - concat, - flatten, - iter, - iteri, - map, - mapi$1 as mapi, - rev_map, - fold_left, - fold_right, - iter2, - map2, - rev_map2, - fold_left2, - fold_right2, - for_all, - exists, - for_all2, - exists2, - mem, - memq, - find, - find_opt, - filter, - find_all, - partition, - assoc, - assoc_opt, - assq, - assq_opt, - mem_assoc, - mem_assq, - remove_assoc, - remove_assq, - split, - combine, - sort, - stable_sort, - fast_sort, - sort_uniq, - merge, -} -/* No side effect */ diff --git a/lib/es6/listLabels.js b/lib/es6/listLabels.js deleted file mode 100644 index 8c89794fad..0000000000 --- a/lib/es6/listLabels.js +++ /dev/null @@ -1,1735 +0,0 @@ - - -import * as Pervasives from "./pervasives.js"; -import * as Caml_option from "./caml_option.js"; - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "hd" - } - }); -} - -function tl(param) { - if (param) { - return param.tl; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "tl" - } - }); -} - -function nth(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "nth" - } - }); - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - if (l2$1) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - } - if (!l2) { - return; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - } - if (!l2) { - return true; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - } - if (!l2) { - return false; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - }; -} - -function mem(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function memq(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function mem_assq(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "listLabels.res", - 420, - 11 - ] - } - }); - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -export { - length, - hd, - compare_lengths, - compare_length_with, - cons, - tl, - nth, - nth_opt, - rev, - init, - append, - rev_append, - concat, - flatten, - iter, - iteri, - map, - mapi$1 as mapi, - rev_map, - fold_left, - fold_right, - iter2, - map2, - rev_map2, - fold_left2, - fold_right2, - for_all, - exists, - for_all2, - exists2, - mem, - memq, - find, - find_opt, - filter, - find_all, - partition, - assoc, - assoc_opt, - assq, - assq_opt, - mem_assoc, - mem_assq, - remove_assoc, - remove_assq, - split, - combine, - sort, - stable_sort, - fast_sort, - sort_uniq, - merge, -} -/* No side effect */ diff --git a/lib/es6/map.js b/lib/es6/map.js deleted file mode 100644 index 2052415d99..0000000000 --- a/lib/es6/map.js +++ /dev/null @@ -1,957 +0,0 @@ - - -import * as Caml_option from "./caml_option.js"; - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/mapLabels.js b/lib/es6/mapLabels.js deleted file mode 100644 index c791c85f85..0000000000 --- a/lib/es6/mapLabels.js +++ /dev/null @@ -1,972 +0,0 @@ - - -import * as Caml_option from "./caml_option.js"; - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (Ord.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - height: height, - create: create, - singleton: singleton, - bal: bal, - empty: "Empty", - is_empty: is_empty, - add: add, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - mem: mem, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - remove_min_binding: remove_min_binding, - remove: remove, - update: update, - iter: iter, - map: map, - mapi: mapi, - fold: fold, - for_all: for_all, - exists: exists, - add_min_binding: add_min_binding, - add_max_binding: add_max_binding, - join: join, - concat: concat, - concat_or_join: concat_or_join, - split: split, - merge: merge$1, - union: union, - filter: filter, - partition: partition, - cons_enum: cons_enum, - compare: compare, - equal: equal, - cardinal: cardinal, - bindings_aux: bindings_aux, - bindings: bindings, - choose: min_binding, - choose_opt: min_binding_opt - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/queue.js b/lib/es6/queue.js deleted file mode 100644 index 72b301fa5f..0000000000 --- a/lib/es6/queue.js +++ /dev/null @@ -1,182 +0,0 @@ - - -import * as Caml_exceptions from "./caml_exceptions.js"; - -let Empty = /* @__PURE__ */Caml_exceptions.create("Queue.Empty"); - -function create() { - return { - length: 0, - first: "Nil", - last: "Nil" - }; -} - -function clear(q) { - q.length = 0; - q.first = "Nil"; - q.last = "Nil"; -} - -function add(x, q) { - let cell = { - TAG: "Cons", - content: x, - next: "Nil" - }; - let last = q.last; - if (typeof last !== "object") { - q.length = 1; - q.first = cell; - q.last = cell; - return; - } - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; -} - -function peek(q) { - let match = q.first; - if (typeof match === "object") { - return match.content; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function take(q) { - let match = q.first; - if (typeof match !== "object") { - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); - } - let content = match.content; - let next = match.next; - if (typeof next !== "object") { - clear(q); - return content; - } - q.length = q.length - 1 | 0; - q.first = next; - return content; -} - -function copy(q) { - let q_res = { - length: q.length, - first: "Nil", - last: "Nil" - }; - let _prev = "Nil"; - let _cell = q.first; - while (true) { - let cell = _cell; - let prev = _prev; - if (typeof cell !== "object") { - q_res.last = prev; - return q_res; - } - let next = cell.next; - let res = { - TAG: "Cons", - content: cell.content, - next: "Nil" - }; - if (typeof prev !== "object") { - q_res.first = res; - } else { - prev.next = res; - } - _cell = next; - _prev = res; - continue; - }; -} - -function is_empty(q) { - return q.length === 0; -} - -function length(q) { - return q.length; -} - -function iter(f, q) { - let _cell = q.first; - while (true) { - let cell = _cell; - if (typeof cell !== "object") { - return; - } - let next = cell.next; - f(cell.content); - _cell = next; - continue; - }; -} - -function fold(f, accu, q) { - let _accu = accu; - let _cell = q.first; - while (true) { - let cell = _cell; - let accu$1 = _accu; - if (typeof cell !== "object") { - return accu$1; - } - let next = cell.next; - let accu$2 = f(accu$1, cell.content); - _cell = next; - _accu = accu$2; - continue; - }; -} - -function transfer(q1, q2) { - if (q1.length <= 0) { - return; - } - let last = q2.last; - if (typeof last !== "object") { - q2.length = q1.length; - q2.first = q1.first; - q2.last = q1.last; - return clear(q1); - } - q2.length = q2.length + q1.length | 0; - last.next = q1.first; - q2.last = q1.last; - clear(q1); -} - -let push = add; - -let pop = take; - -let top = peek; - -export { - Empty, - create, - add, - push, - take, - pop, - peek, - top, - clear, - copy, - is_empty, - length, - iter, - fold, - transfer, -} -/* No side effect */ diff --git a/lib/es6/set.js b/lib/es6/set.js deleted file mode 100644 index 214de70318..0000000000 --- a/lib/es6/set.js +++ /dev/null @@ -1,970 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_option from "./caml_option.js"; - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare = (s1, s2) => { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || funarg.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || funarg.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(funarg.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/setLabels.js b/lib/es6/setLabels.js deleted file mode 100644 index 604cad1ec7..0000000000 --- a/lib/es6/setLabels.js +++ /dev/null @@ -1,1001 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_option from "./caml_option.js"; - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Ord.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || Ord.compare(max_elt(l), v) < 0) && (r === "Empty" || Ord.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - height: height, - create: create, - bal: bal, - add: add, - singleton: singleton, - add_min_element: add_min_element, - add_max_element: add_max_element, - join: join, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - remove_min_elt: remove_min_elt, - merge: merge, - concat: concat, - split: split, - empty: "Empty", - is_empty: is_empty, - mem: mem, - remove: remove, - union: union, - inter: inter, - diff: diff, - cons_enum: cons_enum, - compare_aux: compare_aux, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements_aux: elements_aux, - elements: elements, - choose: min_elt, - choose_opt: min_elt_opt, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - try_join: try_join, - map: map, - of_sorted_list: of_sorted_list, - of_list: of_list - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/stack.js b/lib/es6/stack.js deleted file mode 100644 index 147171622d..0000000000 --- a/lib/es6/stack.js +++ /dev/null @@ -1,90 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; - -let Empty = /* @__PURE__ */Caml_exceptions.create("Stack.Empty"); - -function create() { - return { - c: /* [] */0, - len: 0 - }; -} - -function clear(s) { - s.c = /* [] */0; - s.len = 0; -} - -function copy(s) { - return { - c: s.c, - len: s.len - }; -} - -function push(x, s) { - s.c = { - hd: x, - tl: s.c - }; - s.len = s.len + 1 | 0; -} - -function pop(s) { - let match = s.c; - if (match) { - s.c = match.tl; - s.len = s.len - 1 | 0; - return match.hd; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function top(s) { - let match = s.c; - if (match) { - return match.hd; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function is_empty(s) { - return s.c === /* [] */0; -} - -function length(s) { - return s.len; -} - -function iter(f, s) { - List.iter(f, s.c); -} - -function fold(f, acc, s) { - return List.fold_left(f, acc, s.c); -} - -export { - Empty, - create, - push, - pop, - top, - clear, - copy, - is_empty, - length, - iter, - fold, -} -/* No side effect */ diff --git a/lib/js/complex.js b/lib/js/complex.js deleted file mode 100644 index 6cedfbb02f..0000000000 --- a/lib/js/complex.js +++ /dev/null @@ -1,174 +0,0 @@ -'use strict'; - - -let one = { - re: 1.0, - im: 0.0 -}; - -function add(x, y) { - return { - re: x.re + y.re, - im: x.im + y.im - }; -} - -function sub(x, y) { - return { - re: x.re - y.re, - im: x.im - y.im - }; -} - -function neg(x) { - return { - re: - x.re, - im: - x.im - }; -} - -function conj(x) { - return { - re: x.re, - im: - x.im - }; -} - -function mul(x, y) { - return { - re: x.re * y.re - x.im * y.im, - im: x.re * y.im + x.im * y.re - }; -} - -function div(x, y) { - if (Math.abs(y.re) >= Math.abs(y.im)) { - let r = y.im / y.re; - let d = y.re + r * y.im; - return { - re: (x.re + r * x.im) / d, - im: (x.im - r * x.re) / d - }; - } - let r$1 = y.re / y.im; - let d$1 = y.im + r$1 * y.re; - return { - re: (r$1 * x.re + x.im) / d$1, - im: (r$1 * x.im - x.re) / d$1 - }; -} - -function inv(x) { - return div(one, x); -} - -function norm2(x) { - return x.re * x.re + x.im * x.im; -} - -function norm(x) { - let r = Math.abs(x.re); - let i = Math.abs(x.im); - if (r === 0.0) { - return i; - } - if (i === 0.0) { - return r; - } - if (r >= i) { - let q = i / r; - return r * Math.sqrt(1.0 + q * q); - } - let q$1 = r / i; - return i * Math.sqrt(1.0 + q$1 * q$1); -} - -function arg(x) { - return Math.atan2(x.im, x.re); -} - -function polar(n, a) { - return { - re: Math.cos(a) * n, - im: Math.sin(a) * n - }; -} - -function sqrt(x) { - if (x.re === 0.0 && x.im === 0.0) { - return { - re: 0.0, - im: 0.0 - }; - } - let r = Math.abs(x.re); - let i = Math.abs(x.im); - let w; - if (r >= i) { - let q = i / r; - w = Math.sqrt(r) * Math.sqrt(0.5 * (1.0 + Math.sqrt(1.0 + q * q))); - } else { - let q$1 = r / i; - w = Math.sqrt(i) * Math.sqrt(0.5 * (q$1 + Math.sqrt(1.0 + q$1 * q$1))); - } - if (x.re >= 0.0) { - return { - re: w, - im: 0.5 * x.im / w - }; - } else { - return { - re: 0.5 * i / w, - im: x.im >= 0.0 ? w : - w - }; - } -} - -function exp(x) { - let e = Math.exp(x.re); - return { - re: e * Math.cos(x.im), - im: e * Math.sin(x.im) - }; -} - -function log(x) { - return { - re: Math.log(norm(x)), - im: Math.atan2(x.im, x.re) - }; -} - -function pow(x, y) { - return exp(mul(y, log(x))); -} - -let zero = { - re: 0.0, - im: 0.0 -}; - -let i = { - re: 0.0, - im: 1.0 -}; - -exports.zero = zero; -exports.one = one; -exports.i = i; -exports.neg = neg; -exports.conj = conj; -exports.add = add; -exports.sub = sub; -exports.mul = mul; -exports.inv = inv; -exports.div = div; -exports.sqrt = sqrt; -exports.norm2 = norm2; -exports.norm = norm; -exports.arg = arg; -exports.polar = polar; -exports.exp = exp; -exports.log = log; -exports.pow = pow; -/* No side effect */ diff --git a/lib/js/list.js b/lib/js/list.js deleted file mode 100644 index 1910b1c980..0000000000 --- a/lib/js/list.js +++ /dev/null @@ -1,1733 +0,0 @@ -'use strict'; - -let Pervasives = require("./pervasives.js"); -let Caml_option = require("./caml_option.js"); - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "hd" - } - }); -} - -function tl(param) { - if (param) { - return param.tl; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "tl" - } - }); -} - -function nth(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "nth" - } - }); - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - if (l2$1) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - } - if (!l2) { - return; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - } - if (!l2) { - return true; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - } - if (!l2) { - return false; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function memq(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function mem_assq(x, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "list.res", - 420, - 11 - ] - } - }); - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -exports.length = length; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.hd = hd; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; -exports.concat = concat; -exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi$1; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; -exports.filter = filter; -exports.find_all = find_all; -exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; -exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; -/* No side effect */ diff --git a/lib/js/listLabels.js b/lib/js/listLabels.js deleted file mode 100644 index 54f1a4ab52..0000000000 --- a/lib/js/listLabels.js +++ /dev/null @@ -1,1733 +0,0 @@ -'use strict'; - -let Pervasives = require("./pervasives.js"); -let Caml_option = require("./caml_option.js"); - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "hd" - } - }); -} - -function tl(param) { - if (param) { - return param.tl; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "tl" - } - }); -} - -function nth(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "nth" - } - }); - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth" - } - }); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2" - } - }); -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - if (l2$1) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - } - if (!l2) { - return; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2" - } - }); - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - if (l2) { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - } - if (!l2) { - return true; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2" - } - }); - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - } - if (!l2) { - return false; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2" - } - }); - }; -} - -function mem(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function memq(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function mem_assq(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); - } - if (!l2) { - return /* [] */0; - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine" - } - }); -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "listLabels.res", - 420, - 11 - ] - } - }); - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -exports.length = length; -exports.hd = hd; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; -exports.concat = concat; -exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi$1; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; -exports.filter = filter; -exports.find_all = find_all; -exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; -exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; -/* No side effect */ diff --git a/lib/js/map.js b/lib/js/map.js deleted file mode 100644 index 3588ee0024..0000000000 --- a/lib/js/map.js +++ /dev/null @@ -1,955 +0,0 @@ -'use strict'; - -let Caml_option = require("./caml_option.js"); - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/mapLabels.js b/lib/js/mapLabels.js deleted file mode 100644 index 4094b6e60e..0000000000 --- a/lib/js/mapLabels.js +++ /dev/null @@ -1,970 +0,0 @@ -'use strict'; - -let Caml_option = require("./caml_option.js"); - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal" - } - }); - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ] - } - }); - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (Ord.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - height: height, - create: create, - singleton: singleton, - bal: bal, - empty: "Empty", - is_empty: is_empty, - add: add, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - mem: mem, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - remove_min_binding: remove_min_binding, - remove: remove, - update: update, - iter: iter, - map: map, - mapi: mapi, - fold: fold, - for_all: for_all, - exists: exists, - add_min_binding: add_min_binding, - add_max_binding: add_max_binding, - join: join, - concat: concat, - concat_or_join: concat_or_join, - split: split, - merge: merge$1, - union: union, - filter: filter, - partition: partition, - cons_enum: cons_enum, - compare: compare, - equal: equal, - cardinal: cardinal, - bindings_aux: bindings_aux, - bindings: bindings, - choose: min_binding, - choose_opt: min_binding_opt - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/queue.js b/lib/js/queue.js deleted file mode 100644 index eaf58a010c..0000000000 --- a/lib/js/queue.js +++ /dev/null @@ -1,180 +0,0 @@ -'use strict'; - -let Caml_exceptions = require("./caml_exceptions.js"); - -let Empty = /* @__PURE__ */Caml_exceptions.create("Queue.Empty"); - -function create() { - return { - length: 0, - first: "Nil", - last: "Nil" - }; -} - -function clear(q) { - q.length = 0; - q.first = "Nil"; - q.last = "Nil"; -} - -function add(x, q) { - let cell = { - TAG: "Cons", - content: x, - next: "Nil" - }; - let last = q.last; - if (typeof last !== "object") { - q.length = 1; - q.first = cell; - q.last = cell; - return; - } - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; -} - -function peek(q) { - let match = q.first; - if (typeof match === "object") { - return match.content; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function take(q) { - let match = q.first; - if (typeof match !== "object") { - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); - } - let content = match.content; - let next = match.next; - if (typeof next !== "object") { - clear(q); - return content; - } - q.length = q.length - 1 | 0; - q.first = next; - return content; -} - -function copy(q) { - let q_res = { - length: q.length, - first: "Nil", - last: "Nil" - }; - let _prev = "Nil"; - let _cell = q.first; - while (true) { - let cell = _cell; - let prev = _prev; - if (typeof cell !== "object") { - q_res.last = prev; - return q_res; - } - let next = cell.next; - let res = { - TAG: "Cons", - content: cell.content, - next: "Nil" - }; - if (typeof prev !== "object") { - q_res.first = res; - } else { - prev.next = res; - } - _cell = next; - _prev = res; - continue; - }; -} - -function is_empty(q) { - return q.length === 0; -} - -function length(q) { - return q.length; -} - -function iter(f, q) { - let _cell = q.first; - while (true) { - let cell = _cell; - if (typeof cell !== "object") { - return; - } - let next = cell.next; - f(cell.content); - _cell = next; - continue; - }; -} - -function fold(f, accu, q) { - let _accu = accu; - let _cell = q.first; - while (true) { - let cell = _cell; - let accu$1 = _accu; - if (typeof cell !== "object") { - return accu$1; - } - let next = cell.next; - let accu$2 = f(accu$1, cell.content); - _cell = next; - _accu = accu$2; - continue; - }; -} - -function transfer(q1, q2) { - if (q1.length <= 0) { - return; - } - let last = q2.last; - if (typeof last !== "object") { - q2.length = q1.length; - q2.first = q1.first; - q2.last = q1.last; - return clear(q1); - } - q2.length = q2.length + q1.length | 0; - last.next = q1.first; - q2.last = q1.last; - clear(q1); -} - -let push = add; - -let pop = take; - -let top = peek; - -exports.Empty = Empty; -exports.create = create; -exports.add = add; -exports.push = push; -exports.take = take; -exports.pop = pop; -exports.peek = peek; -exports.top = top; -exports.clear = clear; -exports.copy = copy; -exports.is_empty = is_empty; -exports.length = length; -exports.iter = iter; -exports.fold = fold; -exports.transfer = transfer; -/* No side effect */ diff --git a/lib/js/set.js b/lib/js/set.js deleted file mode 100644 index 3b5ca118c9..0000000000 --- a/lib/js/set.js +++ /dev/null @@ -1,968 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_option = require("./caml_option.js"); - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare = (s1, s2) => { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || funarg.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || funarg.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(funarg.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/setLabels.js b/lib/js/setLabels.js deleted file mode 100644 index 85c913e920..0000000000 --- a/lib/js/setLabels.js +++ /dev/null @@ -1,999 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_option = require("./caml_option.js"); - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal" - } - }); - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt" - } - }); - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Ord.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw new Error("Not_found", { - cause: { - RE_EXN_ID: "Not_found" - } - }); - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || Ord.compare(max_elt(l), v) < 0) && (r === "Empty" || Ord.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ] - } - }); - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - height: height, - create: create, - bal: bal, - add: add, - singleton: singleton, - add_min_element: add_min_element, - add_max_element: add_max_element, - join: join, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - remove_min_elt: remove_min_elt, - merge: merge, - concat: concat, - split: split, - empty: "Empty", - is_empty: is_empty, - mem: mem, - remove: remove, - union: union, - inter: inter, - diff: diff, - cons_enum: cons_enum, - compare_aux: compare_aux, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements_aux: elements_aux, - elements: elements, - choose: min_elt, - choose_opt: min_elt_opt, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - try_join: try_join, - map: map, - of_sorted_list: of_sorted_list, - of_list: of_list - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/stack.js b/lib/js/stack.js deleted file mode 100644 index e90720d44c..0000000000 --- a/lib/js/stack.js +++ /dev/null @@ -1,88 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_exceptions = require("./caml_exceptions.js"); - -let Empty = /* @__PURE__ */Caml_exceptions.create("Stack.Empty"); - -function create() { - return { - c: /* [] */0, - len: 0 - }; -} - -function clear(s) { - s.c = /* [] */0; - s.len = 0; -} - -function copy(s) { - return { - c: s.c, - len: s.len - }; -} - -function push(x, s) { - s.c = { - hd: x, - tl: s.c - }; - s.len = s.len + 1 | 0; -} - -function pop(s) { - let match = s.c; - if (match) { - s.c = match.tl; - s.len = s.len - 1 | 0; - return match.hd; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function top(s) { - let match = s.c; - if (match) { - return match.hd; - } - throw new Error(Empty, { - cause: { - RE_EXN_ID: Empty - } - }); -} - -function is_empty(s) { - return s.c === /* [] */0; -} - -function length(s) { - return s.len; -} - -function iter(f, s) { - List.iter(f, s.c); -} - -function fold(f, acc, s) { - return List.fold_left(f, acc, s.c); -} - -exports.Empty = Empty; -exports.create = create; -exports.push = push; -exports.pop = pop; -exports.top = top; -exports.clear = clear; -exports.copy = copy; -exports.is_empty = is_empty; -exports.length = length; -exports.iter = iter; -exports.fold = fold; -/* No side effect */