From 63f49e62f367cab7dcc20196ec8ff76a4c03ed1a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 11 Aug 2024 17:36:49 +0200 Subject: [PATCH] Remove Js_list, Js_vector --- js/src/js.js | 6 - js/src/js.res | 6 - js/src/js_list.js | 333 ------------------------------------------ js/src/js_list.res | 213 --------------------------- js/src/js_list.resi | 71 --------- js/src/js_vector.js | 134 ----------------- js/src/js_vector.res | 149 ------------------- js/src/js_vector.resi | 92 ------------ 8 files changed, 1004 deletions(-) delete mode 100644 js/src/js_list.js delete mode 100644 js/src/js_list.res delete mode 100644 js/src/js_list.resi delete mode 100644 js/src/js_vector.js delete mode 100644 js/src/js_vector.res delete mode 100644 js/src/js_vector.resi diff --git a/js/src/js.js b/js/src/js.js index f973eb6..bc89eac 100644 --- a/js/src/js.js +++ b/js/src/js.js @@ -59,10 +59,6 @@ let Option; let Result; -let List; - -let Vector; - let Console; let $$Set; @@ -103,8 +99,6 @@ export { Blob, Option, Result, - List, - Vector, Console, $$Set, $$WeakSet, diff --git a/js/src/js.res b/js/src/js.res index 88682d9..052462d 100644 --- a/js/src/js.res +++ b/js/src/js.res @@ -259,12 +259,6 @@ module Option = Js_option /** Define the interface for result */ module Result = Js_result -/** Provide utilities for list */ -module List = Js_list - -/** Provides bindings for JS Vector */ -module Vector = Js_vector - /** Provides bindings for console */ module Console = Js_console diff --git a/js/src/js_list.js b/js/src/js_list.js deleted file mode 100644 index bebfe79..0000000 --- a/js/src/js_list.js +++ /dev/null @@ -1,333 +0,0 @@ - - -import * as Js_vector from "./js_vector.js"; -import * as Caml_option from "rescript/lib/es6/caml_option.js"; - -function length(l) { - let _len = 0; - let _x = l; - while(true) { - let x = _x; - let len = _len; - if (!x) { - return len; - } - _x = x.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(x, xs) { - return { - hd: x, - tl: xs - }; -} - -function isEmpty(x) { - return x === /* [] */0; -} - -function hd(x) { - if (x) { - return Caml_option.some(x.hd); - } - -} - -function tl(x) { - if (x) { - return x.tl; - } - -} - -function nth(l, n) { - if (n < 0) { - return; - } - 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 revAppend(_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 revAppend(l, /* [] */0); -} - -function mapRevAux(f, _acc, _ls) { - while(true) { - let ls = _ls; - let acc = _acc; - if (!ls) { - return acc; - } - _ls = ls.tl; - _acc = { - hd: f(ls.hd), - tl: acc - }; - continue; - }; -} - -function mapRev(f, ls) { - return mapRevAux(f, /* [] */0, ls); -} - -function map(f, ls) { - return revAppend(mapRevAux(f, /* [] */0, ls), /* [] */0); -} - -function iter(f, _x) { - while(true) { - let x = _x; - if (!x) { - return; - } - f(x.hd); - _x = x.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _x = l; - while(true) { - let x = _x; - let i = _i; - if (!x) { - return; - } - f(i, x.hd); - _x = x.tl; - _i = i + 1 | 0; - continue; - }; -} - -function foldLeft(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 tailLoop(f, _acc, _x) { - while(true) { - let x = _x; - let acc = _acc; - if (!x) { - return acc; - } - _x = x.tl; - _acc = f(x.hd, acc); - continue; - }; -} - -function foldRight(f, l, init) { - let loop = function (n, x) { - if (!x) { - return init; - } - let t = x.tl; - let h = x.hd; - if (n < 1000) { - return f(h, loop(n + 1 | 0, t)); - } else { - return f(h, tailLoop(f, init, revAppend(t, /* [] */0))); - } - }; - return loop(0, l); -} - -function flatten(lx) { - let _acc = /* [] */0; - let _lx = lx; - while(true) { - let lx$1 = _lx; - let acc = _acc; - if (!lx$1) { - return revAppend(acc, /* [] */0); - } - _lx = lx$1.tl; - _acc = revAppend(lx$1.hd, acc); - continue; - }; -} - -function filterRevAux(f, _acc, _xs) { - while(true) { - let xs = _xs; - let acc = _acc; - if (!xs) { - return acc; - } - let ys = xs.tl; - let y = xs.hd; - if (f(y)) { - _xs = ys; - _acc = { - hd: y, - tl: acc - }; - continue; - } - _xs = ys; - continue; - }; -} - -function filter(f, xs) { - return revAppend(filterRevAux(f, /* [] */0, xs), /* [] */0); -} - -function filterMapRevAux(f, _acc, _xs) { - while(true) { - let xs = _xs; - let acc = _acc; - if (!xs) { - return acc; - } - let ys = xs.tl; - let z = f(xs.hd); - if (z !== undefined) { - _xs = ys; - _acc = { - hd: Caml_option.valFromOption(z), - tl: acc - }; - continue; - } - _xs = ys; - continue; - }; -} - -function filterMap(f, xs) { - return revAppend(filterMapRevAux(f, /* [] */0, xs), /* [] */0); -} - -function countBy(f, xs) { - let _acc = 0; - let _xs = xs; - while(true) { - let xs$1 = _xs; - let acc = _acc; - if (!xs$1) { - return acc; - } - _xs = xs$1.tl; - _acc = f(xs$1.hd) ? acc + 1 | 0 : acc; - continue; - }; -} - -function init(n, f) { - return Js_vector.toList(Js_vector.init(n, f)); -} - -function toVector(xs) { - if (!xs) { - return []; - } - let a = new Array(length(xs)); - let _i = 0; - let _x = xs; - while(true) { - let x = _x; - let i = _i; - if (!x) { - return a; - } - a[i] = x.hd; - _x = x.tl; - _i = i + 1 | 0; - continue; - }; -} - -function equal(cmp, _xs, _ys) { - while(true) { - let ys = _ys; - let xs = _xs; - if (!xs) { - if (ys) { - return false; - } else { - return true; - } - } - if (!ys) { - return false; - } - if (!cmp(xs.hd, ys.hd)) { - return false; - } - _ys = ys.tl; - _xs = xs.tl; - continue; - }; -} - -export { - length, - cons, - isEmpty, - hd, - tl, - nth, - revAppend, - rev, - mapRev, - map, - iter, - iteri, - foldLeft, - foldRight, - flatten, - filter, - filterMap, - countBy, - init, - toVector, - equal, -} -/* No side effect */ diff --git a/js/src/js_list.res b/js/src/js_list.res deleted file mode 100644 index 8580e6e..0000000 --- a/js/src/js_list.res +++ /dev/null @@ -1,213 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@@warning("-3") - -type t<'a> = list<'a> - -let rec lengthAux = (len, x) => - switch x { - | list{} => len - | list{_, ...l} => lengthAux(len + 1, l) - } - -let length = l => lengthAux(0, l) - -let cons = (x, xs) => list{x, ...xs} - -let isEmpty = x => x == list{} - -let hd = x => - switch x { - | list{} => None - | list{a, ..._} => Some(a) - } - -let tl = x => - switch x { - | list{} => None - | list{_, ...l} => Some(l) - } - -let nth = (l, n) => - if n < 0 { - None - } 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 rec revAppend = (l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => revAppend(l, list{a, ...l2}) - } - -let rev = l => revAppend(l, list{}) - -let rec mapRevAux = (f, acc, ls) => - switch ls { - | list{} => acc - | list{a, ...l} => mapRevAux(f, list{f(a), ...acc}, l) - } - -let mapRev = (f, ls) => mapRevAux(f, list{}, ls) - -let map = (f, ls) => rev(mapRevAux(f, list{}, ls)) - -let rec iter = (f, x) => - switch x { - | list{} => () - | list{a, ...l} => - f(a) - iter(f, l) - } - -let rec iteri = (i, f, x) => - switch x { - | list{} => () - | list{a, ...l} => - f(i, a) - iteri(i + 1, f, l) - } - -let iteri = (f, l) => iteri(0, f, l) - -let rec foldLeft = (f, accu, l) => - switch l { - | list{} => accu - | list{a, ...l} => foldLeft(f, f(accu, a), l) - } - -let foldRightMaxStack = 1000 - -let rec tailLoop = (f, acc, x) => - switch x { - | list{} => acc - | list{h, ...t} => tailLoop(f, f(h, acc), t) - } - -let foldRight = (f, l, init) => { - let rec loop = (n, x) => - switch x { - | list{} => init - | list{h, ...t} => - if n < foldRightMaxStack { - f(h, loop(n + 1, t)) - } else { - f(h, tailLoop(f, init, rev(t))) - } - } - - loop(0, l) -} - -let rec flattenAux = (acc, lx) => - switch lx { - | list{} => rev(acc) - | list{y, ...ys} => flattenAux(revAppend(y, acc), ys) - } - -let flatten = lx => flattenAux(list{}, lx) - -let rec filterRevAux = (f, acc, xs) => - switch xs { - | list{} => acc - | list{y, ...ys} => - switch f(y) { - | false => filterRevAux(f, acc, ys) - | true => filterRevAux(f, list{y, ...acc}, ys) - } - } - -let filter = (f, xs) => rev(filterRevAux(f, list{}, xs)) - -let rec filterMapRevAux = (f: 'a => option<'b>, acc, xs) => - switch xs { - | list{} => acc - | list{y, ...ys} => - switch f(y) { - | None => filterMapRevAux(f, acc, ys) - | Some(z) => filterMapRevAux(f, list{z, ...acc}, ys) - } - } - -let filterMap = (f, xs) => rev(filterMapRevAux(f, list{}, xs)) - -let rec countByAux = (f, acc, xs) => - switch xs { - | list{} => acc - | list{y, ...ys} => - countByAux( - f, - if f(y) { - acc + 1 - } else { - acc - }, - ys, - ) - } - -let countBy = (f, xs) => countByAux(f, 0, xs) - -let init = (n, f) => Js_vector.toList(Js_vector.init(n, f)) - -@new external createUnsafe: int => array<'a> = "Array" - -let toVector = xs => - switch xs { - | list{} => [] - | l => - let a = createUnsafe(length(l)) - let rec fill = (i, x) => - switch x { - | list{} => a - | list{hd, ...tl} => - Js_array2.unsafe_set(a, i, hd) - fill(i + 1, tl) - } - fill(0, l) - } - -let rec equal = (cmp, xs, ys) => - switch (xs, ys) { - | (list{}, list{}) => true - | (list{x, ...xs}, list{y, ...ys}) => - if cmp(x, y) { - equal(cmp, xs, ys) - } else { - false - } - | (_, _) => false - } diff --git a/js/src/js_list.resi b/js/src/js_list.resi deleted file mode 100644 index 4588d37..0000000 --- a/js/src/js_list.resi +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@@deprecated("Use Belt.List instead") - -type t<'a> = list<'a> - -let length: t<'a> => int - -let cons: ('a, t<'a>) => t<'a> - -let isEmpty: t<'a> => bool - -let hd: t<'a> => option<'a> - -let tl: t<'a> => option> - -let nth: (t<'a>, int) => option<'a> - -let revAppend: (t<'a>, t<'a>) => t<'a> - -let rev: t<'a> => t<'a> - -let mapRev: ('a => 'b, t<'a>) => t<'b> - -let map: ('a => 'b, t<'a>) => t<'b> - -let iter: ('a => unit, t<'a>) => unit - -let iteri: ((int, 'a) => unit, t<'a>) => unit - -/** Application order is left to right, tail recurisve */ -let foldLeft: (('a, 'b) => 'a, 'a, list<'b>) => 'a - -/** Application order is right to left tail-recursive. */ -let foldRight: (('a, 'b) => 'b, list<'a>, 'b) => 'b - -let flatten: t> => t<'a> - -let filter: ('a => bool, t<'a>) => t<'a> - -let filterMap: ('a => option<'b>, t<'a>) => t<'b> - -let countBy: ('a => bool, list<'a>) => int - -let init: (int, int => 'a) => t<'a> - -let toVector: t<'a> => array<'a> - -let equal: (('a, 'a) => bool, list<'a>, list<'a>) => bool diff --git a/js/src/js_vector.js b/js/src/js_vector.js deleted file mode 100644 index ccbecab..0000000 --- a/js/src/js_vector.js +++ /dev/null @@ -1,134 +0,0 @@ - - - -function filterInPlace(p, a) { - let i = 0; - let j = 0; - while(i < a.length) { - let v = a[i]; - if (p(v)) { - a[j] = v; - j = j + 1 | 0; - } - i = i + 1 | 0; - }; - a.splice(j); -} - -function empty(a) { - a.splice(0); -} - -function pushBack(x, xs) { - xs.push(x); -} - -function memByRef(x, xs) { - return xs.indexOf(x) >= 0; -} - -function iter(f, xs) { - for(let i = 0 ,i_finish = xs.length; i < i_finish; ++i){ - f(xs[i]); - } -} - -function iteri(f, a) { - for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ - f(i, a[i]); - } -} - -function toList(a) { - let _i = a.length - 1 | 0; - let _res = /* [] */0; - while(true) { - let res = _res; - let i = _i; - if (i < 0) { - return res; - } - _res = { - hd: a[i], - tl: res - }; - _i = i - 1 | 0; - continue; - }; -} - -function init(n, f) { - let v = new Array(n); - for(let i = 0; i < n; ++i){ - v[i] = f(i); - } - return v; -} - -function copy(x) { - let len = x.length; - let b = new Array(len); - for(let i = 0; i < len; ++i){ - b[i] = x[i]; - } - return b; -} - -function map(f, a) { - let l = a.length; - let r = new Array(l); - for(let i = 0; i < l; ++i){ - r[i] = f(a[i]); - } - return r; -} - -function foldLeft(f, x, a) { - let r = x; - for(let i = 0 ,i_finish = a.length; i < i_finish; ++i){ - r = f(r, a[i]); - } - return r; -} - -function foldRight(f, a, x) { - let r = x; - for(let i = a.length - 1 | 0; i >= 0; --i){ - r = f(a[i], r); - } - return r; -} - -function mapi(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let r = new Array(l); - for(let i = 0; i < l; ++i){ - r[i] = f(i, a[i]); - } - return r; -} - -function append(x, a) { - return a.concat([x]); -} - -export { - filterInPlace, - empty, - pushBack, - copy, - memByRef, - iter, - iteri, - toList, - map, - mapi, - foldLeft, - foldRight, - init, - append, -} -/* No side effect */ diff --git a/js/src/js_vector.res b/js/src/js_vector.res deleted file mode 100644 index 568e803..0000000 --- a/js/src/js_vector.res +++ /dev/null @@ -1,149 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type t<'a> = array<'a> - -external length: array<'a> => int = "%array_length" -external get: (array<'a>, int) => 'a = "%array_safe_get" -external set: (array<'a>, int, 'a) => unit = "%array_safe_set" -external make: (int, 'a) => array<'a> = "?make_vect" -external unsafe_get: (t<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (t<'a>, int, 'a) => unit = "%array_unsafe_set" - -/** -**param** a array - -**param** p predicate -*/ -let filterInPlace = (p, a) => { - let i = ref(0) - let j = ref(0) - while i.contents < Js_array2.length(a) { - let v = Js_array2.unsafe_get(a, i.contents) - if p(v) { - Js_array2.unsafe_set(a, j.contents, v) - j.contents = j.contents + 1 - } - i.contents = i.contents + 1 - } - Js_array2.removeFromInPlace(a, ~pos=j.contents)->ignore -} - -let empty = a => Js_array2.removeFromInPlace(a, ~pos=0)->ignore - -let pushBack = (x, xs) => Js_array2.push(xs, x)->ignore - -/** Find by JS (===) equality */ -let memByRef = (x, xs) => Js_array2.indexOf(xs, x) >= 0 - -let iter = (f, xs) => - for i in 0 to Js_array2.length(xs) - 1 { - f(Js_array2.unsafe_get(xs, i)) - } - -let iteri = (f, a) => - for i in 0 to length(a) - 1 { - f(i, unsafe_get(a, i)) - } - -@new external createUnsafe: int => t<'a> = "Array" - -/* let ofList xs = */ -/* match xs with */ -/* | [] -> [||] */ -/* | l -> */ -/* let a = createUnsafe (Js_list.length l) in */ -/* let rec fill i = function */ -/* | [] -> a */ -/* | hd::tl -> Array.unsafe_set a i hd; fill (i+1) tl in */ -/* fill 0 l */ - -let toList = a => { - let rec tolist = (i, res) => - if i < 0 { - res - } else { - tolist(i - 1, list{unsafe_get(a, i), ...res}) - } - tolist(length(a) - 1, list{}) -} - -let init = (n, f) => { - let v = createUnsafe(n) - for i in 0 to n - 1 { - unsafe_set(v, i, f(i)) - } - v -} - -let copy = x => { - let len = length(x) - let b = createUnsafe(len) - for i in 0 to len - 1 { - unsafe_set(b, i, unsafe_get(x, i)) - } - b -} - -let map = (f, a) => { - let l = Js_array2.length(a) - let r = createUnsafe(l) - for i in 0 to l - 1 { - unsafe_set(r, i, f(unsafe_get(a, i))) - } - r -} - -let foldLeft = (f, x, a) => { - let r = ref(x) - for i in 0 to length(a) - 1 { - r.contents = f(r.contents, unsafe_get(a, i)) - } - r.contents -} - -let foldRight = (f, a, x) => { - let r = ref(x) - for i in length(a) - 1 downto 0 { - r.contents = f(unsafe_get(a, i), r.contents) - } - r.contents -} - -let mapi = (f, a) => { - let l = length(a) - if l == 0 { - [] - } else { - let r = createUnsafe(l) - for i in 0 to l - 1 { - unsafe_set(r, i, f(i, unsafe_get(a, i))) - } - r - } -} - -let append = (x, a) => Js_array2.concat(a, [x]) - -/* TODO: add `append` */ diff --git a/js/src/js_vector.resi b/js/src/js_vector.resi deleted file mode 100644 index b36045c..0000000 --- a/js/src/js_vector.resi +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@@deprecated("Use Belt.Array instead") - -type t<'a> = array<'a> - -let filterInPlace: ('a => bool, t<'a>) => unit -let empty: t<'a> => unit -let pushBack: ('a, t<'a>) => unit - -/** shallow copy */ -let copy: t<'a> => t<'a> - -let memByRef: ('a, t<'a>) => bool -let iter: ('a => unit, t<'a>) => unit -let iteri: ((int, 'a) => unit, t<'a>) => unit - -/* [@@deprecated "Use Js.List.toVector instead"] */ -/* val ofList : 'a list -> 'a t */ -/* removed, we choose that [`Js.List`]() depends on Vector to avoid cylic dependency - */ - -let toList: t<'a> => list<'a> -let map: ('a => 'b, t<'a>) => t<'b> -let mapi: ((int, 'a) => 'b, t<'a>) => t<'b> -let foldLeft: (('a, 'b) => 'a, 'a, t<'b>) => 'a -let foldRight: (('b, 'a) => 'a, t<'b>, 'a) => 'a - -/** Return the length (number of elements) of the given array. */ -external length: t<'a> => int = "%array_length" - -/** -`Vector.get(a, n)` returns the element number `n` of vector `a`. The first -element has number 0. The last element has number `Vector.length(a) - 1`. You -can also write `a[n]` instead of `Vector.get(a, n)`. Raise `Invalid_argument -"index out of bounds"` if `n` is outside the range 0 to (`Array.length(a) - -1`). -*/ -external get: (t<'a>, int) => 'a = "%array_safe_get" - -/** -`Vector.set(a, n, x)` modifies vector `a` in place, replacing element number -`n` with `x`. Raise `Invalid_argument "index out of bounds"` if `n` is outside -the range 0 to `Array.length(a) - 1`. -*/ -external set: (t<'a>, int, 'a) => unit = "%array_safe_set" - -/** -`Vector.make(n, x)` returns a fresh vector of length `n`, initialized with `x`. -All the elements of this new vector are initially physically equal to `x` (in -the sense of the `==` predicate). Consequently, if `x` is mutable, it is shared -among all elements of the array, and modifying `x` through one of the array -entries will modify all other entries at the same time. Raise -`Invalid_argument` if `n < 0` or `n > Sys.max_array_length`. If the value of -`x` is a floating-point number, then the maximum size is only -`Sys.max_array_length / 2`. -*/ -external make: (int, 'a) => t<'a> = "?make_vect" - -/** -Raises `RangeError` when n is negative. -n : size -*/ -let init: (int, int => 'a) => t<'a> - -/** `append(x, a)` returns a fresh vector with `x` appended to `a`. */ -let append: ('a, t<'a>) => t<'a> - -external unsafe_get: (t<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (t<'a>, int, 'a) => unit = "%array_unsafe_set"