From 366dbeddb0b5e4ffd7068fd8e7e2ca71a6836b6f Mon Sep 17 00:00:00 2001 From: Stefan Fehrenbach Date: Sat, 28 May 2022 14:49:29 +0200 Subject: [PATCH] Purescript v0.15 changes --- Makefile | 13 +++++++------ bench/Main.js | 6 +++--- bower.json | 32 +++++++++++++++--------------- shell.nix | 2 +- src/Data/HashMap.js | 44 +++++++++++++++++++----------------------- src/Data/Hashable.js | 4 ++-- src/Data/Hashable.purs | 10 +++++----- 7 files changed, 54 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index b1a21c3..095a4e0 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,10 @@ output/Bench.Main/index.js: $(SOURCES) $(BENCH_SOURCES) $(BOWER_SOURCES) purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs' bench: output/Bench.Main/index.js - node --expose-gc -e 'require("./output/Bench.Main/index.js").main()' + node --expose-gc -e 'import("./output/Bench.Main/index.js").then(m => m.main())' bench-trace: output/Bench.Main/index.js - node --expose-gc --trace-opt --trace-deopt --print-opt-code --code-comments -e 'require("./output/Bench.Main/index.js").main()' + node --expose-gc --trace-opt --trace-deopt --print-opt-code --code-comments -e 'import("./output/Bench.Main/index.js").then(m => m.main())' compile: $(SOURCES) $(BOWER_SOURCES) purs compile 'src/**/*.purs' 'bower_components/*/src/**/*.purs' @@ -23,11 +23,12 @@ output/Test.Main/index.js: compile $(SOURCES) $(TEST_SOURCES) $(BOWER_SOURCES) purs compile 'test/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs' test: output/Test.Main/index.js - node -e 'require("./output/Test.Main/index.js").main()' + node -e 'import("./output/Test.Main/index.js").then(m => m.main())' -test-bundle: output/Test.Main/index.js - purs bundle 'output/**/*.js' --output test-bundle.js --module Test.Main --main Test.Main - node test-bundle.js +# No more purs bundle in Purescript v0.15. +# test-bundle: output/Test.Main/index.js +# purs bundle 'output/**/*.js' --output test-bundle.js --module Test.Main --main Test.Main +# node test-bundle.js clean: rm -rf bower_components/ output/ diff --git a/bench/Main.js b/bench/Main.js index 1ec13ce..d3a8be6 100644 --- a/bench/Main.js +++ b/bench/Main.js @@ -1,10 +1,10 @@ -exports.table = function (t) { +export function table(t) { return function () { console.table(t); }; }; -exports.shuffle = function (input) { +export function shuffle(input) { return function () { var a = input.slice(); var j, x, i; @@ -18,7 +18,7 @@ exports.shuffle = function (input) { }; } -exports.bulkLoadStringKeysObj = function (arr) { +export function bulkLoadStringKeysObj(arr) { var m = {}; for (var i = 0; i < arr.length; i++) m[arr[i]+""] = i*10; diff --git a/bower.json b/bower.json index 94c9335..9953666 100644 --- a/bower.json +++ b/bower.json @@ -12,23 +12,23 @@ "output" ], "dependencies": { - "purescript-arrays": "^6.0.0", - "purescript-enums": "^5.0.0", - "purescript-functions": "^5.0.0", - "purescript-integers": "^5.0.0", - "purescript-lists": "^6.0.0", - "purescript-prelude": "^5.0.0", - "purescript-record": "^3.0.0", - "purescript-tuples": "^6.0.0", - "purescript-typelevel-prelude": "^6.0.0", - "purescript-unfoldable": "^5.0.0" + "purescript-arrays": "^7.0.0", + "purescript-enums": "^6.0.0", + "purescript-functions": "^6.0.0", + "purescript-integers": "^6.0.0", + "purescript-lists": "^7.0.0", + "purescript-prelude": "^6.0.0", + "purescript-record": "^4.0.0", + "purescript-tuples": "^7.0.0", + "purescript-typelevel-prelude": "^7.0.0", + "purescript-unfoldable": "^6.0.0" }, "devDependencies": { - "purescript-foreign-object": "^3.0.0", - "purescript-minibench": "^3.0.0", - "purescript-ordered-collections": "^2.0.0", - "purescript-psci-support": "^5.0.0", - "purescript-quickcheck": "^7.0.0", - "purescript-st": "v5.0.0" + "purescript-foreign-object": "^4.0.0", + "purescript-minibench": "^4.0.0", + "purescript-ordered-collections": "^3.0.0", + "purescript-psci-support": "^6.0.0", + "purescript-quickcheck": "^8.0.0", + "purescript-st": "^6.0.0" } } diff --git a/shell.nix b/shell.nix index ba849d8..634d8fa 100644 --- a/shell.nix +++ b/shell.nix @@ -1,6 +1,6 @@ let pkgs = import {}; - easy-ps = import (fetchTarball https://github.com/justinwoo/easy-purescript-nix/archive/d0f592b71b2be222f8dcfb4f4cefb52608bbc1ae.tar.gz) { inherit pkgs; }; + easy-ps = import (fetchTarball https://github.com/justinwoo/easy-purescript-nix/archive/cbcb53725c430de4e69f652d69c1677e17c6bcec.tar.gz) { inherit pkgs; }; in pkgs.stdenv.mkDerivation { name = "purescript-unordered-collections-shell"; buildInputs = [ diff --git a/src/Data/HashMap.js b/src/Data/HashMap.js index 6540377..65f179e 100644 --- a/src/Data/HashMap.js +++ b/src/Data/HashMap.js @@ -762,17 +762,15 @@ function insert2remove1(a, insertIndex, v1, v2, removeIndex) { return res; } -var empty = new MapNode(0,0,[]); +export const empty = new MapNode(0,0,[]); -exports.empty = empty; - -exports.lookupPurs = function (Nothing, Just, keyEquals, key, keyHash) { +export function lookupPurs(Nothing, Just, keyEquals, key, keyHash) { return function (m) { return m.lookup(Nothing, Just, keyEquals, key, keyHash, 0); }; }; -exports.fromArrayPurs = function (keyEquals, hashFunction) { +export function fromArrayPurs(keyEquals, hashFunction) { return function (kf) { return function (vf) { return function (a) { @@ -788,7 +786,7 @@ exports.fromArrayPurs = function (keyEquals, hashFunction) { }; }; -exports.insertPurs = function (keyEquals, hashFunction) { +export function insertPurs(keyEquals, hashFunction) { return function (key) { return function (value) { return function (m) { @@ -798,7 +796,7 @@ exports.insertPurs = function (keyEquals, hashFunction) { }; }; -exports.insertWithPurs = function (keyEquals, hashFunction) { +export function insertWithPurs(keyEquals, hashFunction) { return function (f) { return function (key) { return function (value) { @@ -810,13 +808,13 @@ exports.insertWithPurs = function (keyEquals, hashFunction) { }; }; -exports.deletePurs = function (keyEquals, key, keyHash) { +export function deletePurs(keyEquals, key, keyHash) { return function (m) { return m.delet(keyEquals, key, keyHash, 0); }; }; -exports.unionWithPurs = function (eq, hash, f) { +export function unionWithPurs(eq, hash, f) { return function (l) { return function (r) { return l.unionWith(eq, hash, f, r, 0); @@ -824,7 +822,7 @@ exports.unionWithPurs = function (eq, hash, f) { }; }; -exports.intersectionWithPurs = function (Nothing, Just, eq, hash, f) { +export function intersectionWithPurs(Nothing, Just, eq, hash, f) { return function (l) { return function (r) { return l.intersectionWith(Nothing, Just, eq, hash, f, r, 0); @@ -832,7 +830,7 @@ exports.intersectionWithPurs = function (Nothing, Just, eq, hash, f) { }; }; -exports.toArrayBy = function (f) { +export function toArrayBy(f) { return function (m) { var res = []; m.toArrayBy(f, res); @@ -840,11 +838,11 @@ exports.toArrayBy = function (f) { }; }; -exports.debugShow = function (m) { +export function debugShow(m) { return JSON.stringify(m); } -exports.singletonPurs = function (k) { +export function singletonPurs(k) { return function (keyHash) { return function (v) { return new MapNode(1 << (keyHash & 31), 0, [k, v]); @@ -852,7 +850,7 @@ exports.singletonPurs = function (k) { }; }; -exports.eqPurs = function (keq, veq) { +export function eqPurs(keq, veq) { return function (a) { return function (b) { return a.eq(keq, veq, b); @@ -860,21 +858,19 @@ exports.eqPurs = function (keq, veq) { }; }; -function isEmpty (m) { +export function isEmpty (m) { return m.datamap === 0 && m.nodemap === 0; } -exports.isEmpty = isEmpty; - -exports.size = function (m) { return m.size(); } +export function size(m) { return m.size(); } -exports.mapWithIndexPurs = function (f) { +export function mapWithIndexPurs(f) { return function (m) { return m.imap(f); }; }; -exports.foldMapWithIndexPurs = function (mempty) { +export function foldMapWithIndexPurs(mempty) { return function (mappend) { return function (f) { return function (m) { @@ -884,7 +880,7 @@ exports.foldMapWithIndexPurs = function (mempty) { }; }; -exports.traverseWithIndexPurs = function (pure) { +export function traverseWithIndexPurs(pure) { return function (apply) { return function (f) { return function (m) { @@ -894,19 +890,19 @@ exports.traverseWithIndexPurs = function (pure) { }; }; -exports.hashPurs = function (vhash) { +export function hashPurs(vhash) { return function (m) { return m.hash(vhash); }; }; -exports.filterWithKey = function (f) { +export function filterWithKey(f) { return function (m) { return m.filterWithKey(f); }; }; -exports.nubHashPurs = function (Nothing, Just, eq, hash) { +export function nubHashPurs(Nothing, Just, eq, hash) { return function (a) { var m = new MapNode(0,0,[]); var r = []; diff --git a/src/Data/Hashable.js b/src/Data/Hashable.js index 5c02b60..dd9ad18 100644 --- a/src/Data/Hashable.js +++ b/src/Data/Hashable.js @@ -4,7 +4,7 @@ "use strict"; -exports.hashNumber = function (o) { +export function hashNumber(o) { if (o !== o || o === Infinity) { return 0; } @@ -19,7 +19,7 @@ exports.hashNumber = function (o) { return h; }; -exports.hashString = function (s) { +export function hashString(s) { var h = 0; for (var i = 0; i < s.length; i++) { h = (31 * h + s.charCodeAt(i)) | 0; diff --git a/src/Data/Hashable.purs b/src/Data/Hashable.purs index ff69d6d..a2326c7 100644 --- a/src/Data/Hashable.purs +++ b/src/Data/Hashable.purs @@ -24,8 +24,8 @@ import Data.Tuple (Tuple(..)) import Prim.Row as Row import Prim.RowList (class RowToList, Cons, Nil) import Record (get) -import Type.Data.RowList (RLProxy(..)) -import Type.Prelude (class IsSymbol, SProxy(..)) +import Type.Prelude (class IsSymbol) +import Type.Proxy (Proxy(..)) -- | The `Hashable` type class represents types with decidable -- | equality and a hash function for use in hash-based algorithms and @@ -106,7 +106,7 @@ instance hashableVoid :: Hashable Void where -- hash = fromEnum class EqRecord l r <= HashableRecord l r | l -> r where - hashRecord :: RLProxy l -> Record r -> Int + hashRecord :: Proxy l -> Record r -> Int instance hashableRecordNil :: HashableRecord Nil r where hashRecord _ _ = 0 @@ -117,11 +117,11 @@ instance hashableRecordCons :: , IsSymbol l , Row.Cons l vt whatev r ) => HashableRecord (Cons l vt tl) r where - hashRecord _ record = hash (get (SProxy :: SProxy l) record) * 31 + hashRecord (RLProxy :: RLProxy tl) record + hashRecord _ record = hash (get (Proxy :: Proxy l) record) * 31 + hashRecord (Proxy :: Proxy tl) record instance hashableRecord :: (RowToList r l, HashableRecord l r, EqRecord l r) => Hashable (Record r) where - hash = hashRecord (RLProxy :: RLProxy l) + hash = hashRecord (Proxy :: Proxy l) -- TODO add combinators and a generics-rep implementation