Skip to content

Commit

Permalink
Purescript v0.15 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fehrenbach committed May 28, 2022
1 parent 1be2891 commit 366dbed
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 57 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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/
6 changes: 3 additions & 3 deletions bench/Main.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let
pkgs = import <nixpkgs> {};
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 = [
Expand Down
44 changes: 20 additions & 24 deletions src/Data/HashMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -810,71 +808,69 @@ 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);
};
};
};

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);
};
};
};

exports.toArrayBy = function (f) {
export function toArrayBy(f) {
return function (m) {
var res = [];
m.toArrayBy(f, res);
return res;
};
};

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]);
};
};
};

exports.eqPurs = function (keq, veq) {
export function eqPurs(keq, veq) {
return function (a) {
return function (b) {
return a.eq(keq, veq, b);
};
};
};

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) {
Expand All @@ -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) {
Expand All @@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Hashable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"use strict";

exports.hashNumber = function (o) {
export function hashNumber(o) {
if (o !== o || o === Infinity) {
return 0;
}
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/Data/Hashable.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 366dbed

Please sign in to comment.