git.iko.soy/rowtype-yoga/purescript-unique
on master help sign in
26 files changed+536−174
since splitsnapshots
unifiedsplit
.editorconfig+13 .envrc+9 .github/ISSUE_TEMPLATE/bug-report.md+23 .github/ISSUE_TEMPLATE/change-request.md+24 .github/ISSUE_TEMPLATE/config.yml+8 .github/PULL_REQUEST_TEMPLATE.md+12 .github/workflows/ci.yml+57 .gitignore+9−5 .tidyrc.json+10 CHANGELOG.md+80 CONTRIBUTING.md+50 LICENSE+22 MODULE.md−48 README.md+41−4 bower.json+14−9 docs/README.md+3 gulpfile.js−52 package.json+8−12 packages.dhall+5 purs.json+22 shell.nix+28 spago.dhall+5 src/Data/Unique.js+29 src/Data/Unique.purs+41−44 test.dhall+6 test/Main.purs+17
.editorconfignew file+13
@@ -0,0 +1,13 @@
1+# https://editorconfig.org
2+root = true
3+
4+[*]
5+indent_style = space
6+indent_size = 2
7+end_of_line = lf
8+charset = utf-8
9+trim_trailing_whitespace = true
10+insert_final_newline = true
11+
12+[*.md]
13+trim_trailing_whitespace = false
.envrcnew file+9
@@ -0,0 +1,9 @@
1+#!/usr/bin/env bash
2+
3+if command -v lorri;
4+then
5+ eval "$(lorri direnv)"
6+elif command -v nix-shell
7+then
8+ use nix
9+fi
.github/ISSUE_TEMPLATE/bug-report.mdnew file+23
@@ -0,0 +1,23 @@
1+---
2+name: Bug report
3+about: Report an issue
4+title: ""
5+labels: bug
6+assignees: ""
7+---
8+
9+**Describe the bug**
10+
11+A clear and concise description of the bug.
12+
13+**To Reproduce**
14+
15+A minimal code example (preferably a runnable example on [Try PureScript](https://try.purescript.org)!) or steps to reproduce the issue.
16+
17+**Expected behavior**
18+
19+A clear and concise description of what you expected to happen.
20+
21+**Additional context**
22+
23+Add any other context about the problem here.
.github/ISSUE_TEMPLATE/change-request.mdnew file+24
@@ -0,0 +1,24 @@
1+---
2+name: Change request
3+about: Propose an improvement to this library
4+title: ""
5+labels: ""
6+assignees: ""
7+---
8+
9+**Is your change request related to a problem? Please describe.**
10+
11+A clear and concise description of the problem.
12+
13+Examples:
14+
15+- It's frustrating to have to [...]
16+- I was looking for a function to [...]
17+
18+**Describe the solution you'd like**
19+
20+A clear and concise description of what a good solution to you looks like, including any solutions you've already considered.
21+
22+**Additional context**
23+
24+Add any other context about the change request here.
.github/ISSUE_TEMPLATE/config.ymlnew file+8
@@ -0,0 +1,8 @@
1+blank_issues_enabled: false
2+contact_links:
3+ - name: PureScript Discourse
4+ url: https://discourse.purescript.org/
5+ about: Ask and answer questions on the PureScript discussion forum.
6+ - name: PureScript Discord
7+ url: https://purescript.org/chat
8+ about: Ask and answer questions on the PureScript chat.
.github/PULL_REQUEST_TEMPLATE.mdnew file+12
@@ -0,0 +1,12 @@
1+**Description of the change**
2+
3+Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR.
4+
5+---
6+
7+**Checklist:**
8+
9+- [ ] Added the change to the changelog's "Unreleased" section with a link to this PR and your username
10+- [ ] Linked any existing issues or proposals that this pull request should close
11+- [ ] Updated or added relevant documentation in the README and/or documentation directory
12+- [ ] Added a test for the contribution (if applicable)
.github/workflows/ci.ymlnew file+57
@@ -0,0 +1,57 @@
1+name: CI
2+
3+on:
4+ push:
5+ branches: [master]
6+ paths:
7+ - 'src/**/*.purs'
8+ - 'src/**/*.js'
9+ - 'test/**/*.purs'
10+ - 'test/**/*.js'
11+ - '*.dhall'
12+ - '*.json'
13+ - '.github/workflows/ci.yml'
14+ pull_request:
15+ branches: [master]
16+ paths:
17+ - 'src/**/*.purs'
18+ - 'src/**/*.js'
19+ - 'test/**/*.purs'
20+ - 'test/**/*.js'
21+ - '*.dhall'
22+ - '*.json'
23+ - '.github/workflows/ci.yml'
24+
25+jobs:
26+ build:
27+ runs-on: ubuntu-latest
28+
29+ steps:
30+ - uses: actions/checkout@v3
31+
32+ - uses: purescript-contrib/setup-purescript@main
33+ with:
34+ purescript: "unstable"
35+ purs-tidy: "latest"
36+
37+ - uses: actions/cache@v2
38+ with:
39+ key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
40+ path: |
41+ .spago
42+ output
43+
44+ - run: spago install
45+
46+ - run: spago build --no-install --purs-args '--censor-lib --strict'
47+
48+ - run: spago -x test.dhall test
49+
50+ - run: purs-tidy check src test
51+
52+ - name: Verify Bower & Pulp
53+ run: |
54+ npm install bower pulp@16.0.0-0
55+ npx bower install
56+ npx pulp build # -- --censor-lib --strict
57+ npx pulp test
.gitignore+9−5
@@ -1,5 +1,9 @@
1−/bower_components
2−/node_modules
3−/.psci_modules
4−/output
5−/.psci
1+.*
2+!.gitignore
3+!.github
4+!.editorconfig
5+!.tidyrc.json
6+
7+output
8+generated-docs
9+bower_components
.tidyrc.jsonnew file+10
@@ -0,0 +1,10 @@
1+{
2+ "importSort": "source",
3+ "importWrap": "source",
4+ "indent": 2,
5+ "operatorsFile": null,
6+ "ribbon": 1,
7+ "typeArrowPlacement": "first",
8+ "unicode": "never",
9+ "width": null
10+}
CHANGELOG.mdnew file+80
@@ -0,0 +1,80 @@
1+# Changelog
2+
3+Notable changes are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4+
5+## [Unreleased]
6+
7+Breaking changes:
8+
9+New features:
10+
11+Bugfixes:
12+
13+Other improvements:
14+- Updated the project for its new home in the Rowtype Yoga organization. ([50e18df](https://github.com/rowtype-yoga/purescript-unique/commit/50e18dfe14082186abc103b3c969343cf998cad0) by @nsaunders)
15+
16+## [0.6.1] - 2023-03-18
17+
18+New features:
19+- Added `hashUnique` function. (#4 by @nsaunders)
20+
21+Other improvements:
22+- Changed `Unique`'s runtime representation to a [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt). (#4 by @nsaunders)
23+- Updated the project to the standards of the [purescript-contrib](https://github.com/purescript-contrib) organization. ([8ec352b](https://github.com/rowtype-yoga/purescript-unique/commit/8ec352ba1f7076c57c776872c2bc8ce7eb530e44) by @nsaunders)
24+
25+## [0.6.0] - 2023-03-02
26+
27+Breaking changes:
28+- Updated to v0.15 of the compiler, dropping support for previous versions. ([7999c18](https://github.com/rowtype-yoga/purescript-unique/commit/7999c1815adeb9011124c7d54902b55f18c8f295) by @nsaunders)
29+
30+## [0.5.1] - 2023-03-02
31+
32+Other improvements:
33+- Added `purs.json` file to facilitate package name transfer. ([4c40891](https://github.com/rowtype-yoga/purescript-unique/commit/4c40891f563c3e5f212fe3b0cef4c0c28dd917b8) by @nsaunders)
34+- Added `LICENSE` file, determined from `bower.json`. ([2f3305c](https://github.com/rowtype-yoga/purescript-unique/commit/2f3305cb511e6c270c25d53e6ebaaf3c193646ae) by @nsaunders)
35+
36+## [0.5.0] - 2017-04-26
37+
38+Breaking changes:
39+- Updated to v0.11 of the compiler, dropping support for previous versions. ([33214fa](https://github.com/rowtype-yoga/purescript-unique/commit/33214faf821843aad95a019ad0a4a28d2b305189) by @mechairoi)
40+
41+## [0.4.0] - 2017-01-06
42+
43+Other improvements:
44+- Updated dependencies. ([03a24af](https://github.com/rowtype-yoga/purescript-unique/commit/03a24af23dd9a64e08ff8a9f8d119437d2d9cf44) by @mechairoi)
45+
46+## [0.3.0] - 2016-06-28
47+
48+Breaking changes:
49+- Updated to v0.9 of the compiler, dropping support for previous versions. ([3a58d82](https://github.com/rowtype-yoga/purescript-unique/commit/3a58d82f1d9b5942cc29f3a31979a10978797204) by @mechairoi)
50+
51+## [0.2.3] - 2016-05-04
52+
53+Breaking changes:
54+- Updated to v0.8 of the compiler, dropping support for previous versions. ([42fecfe](https://github.com/rowtype-yoga/purescript-unique/commit/42fecfef16b3f54e7bf52ba8e882202f5f73fe6b) by @mechairoi)
55+
56+## [0.2.2] - 2016-02-12
57+
58+Bugfixes:
59+- Fixed `bower.json`. ([5048080](https://github.com/rowtype-yoga/purescript-unique/commit/5048080a43a552e5a4786aff4bd4ae93816ade0f) by @mechairoi)
60+
61+Other improvements:
62+- Updated to use Pursuit for docs. ([de69519](https://github.com/rowtype-yoga/purescript-unique/commit/de695190c6bf43d827f0e63c0c99a6e080b262cc) by @mechairoi)
63+
64+## [0.2.1] - 2016-02-12
65+
66+No significant changes in this release.
67+
68+## [0.2.0] - 2016-02-12
69+
70+Breaking changes:
71+- Renamed `Uniq` effect to `UNIQ`. ([4eeac9f](https://github.com/rowtype-yoga/purescript-unique/commit/4eeac9f11f79b85bf8086d869ffa8fa56d9a9ec0) by @mechairoi)
72+
73+## [0.1.0] - 2015-08-09
74+
75+Breaking changes:
76+- Updated to v0.7 of the compiler, dropping support for previous versions. ([d2b2873](https://github.com/rowtype-yoga/purescript-unique/commit/d2b2873559a8c1bfe7dd3194a1614a77eac1a01e) by @mechairoi)
77+
78+## [0.0.1] - 2015-08-09
79+
80+Initial release
CONTRIBUTING.mdnew file+50
@@ -0,0 +1,50 @@
1+Contributing
2+============
3+
4+Welcome, and thanks for your interest in Unique. Whether you are new to PureScript or here to teach us new tricks, we're glad to have you and look forward to your contributions. Listed below are a few ways you can help.
5+
6+Asking questions
7+----------------
8+If you have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=question) to discuss it. This might help us to find a defect; reveal an opportunity to improve the documentation or developer experience; or help someone facing a similar issue in the future.
9+
10+Reporting bugs
11+--------------
12+Please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=bug&template=bug-report.md) to discuss any defects you find.
13+
14+Enhancements
15+------------
16+Please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=enhancement&template=change-request.md) to discuss potential enhancements to the library. When submitting design ideas, please note that, for the most part, this library is intended as a direct port of the Haskell [`Data.Unique`](https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-Unique.html) module.
17+
18+Improving documentation
19+-----------------------
20+Please share any suggestions for improving or adding to the documentation by [submitting a pull request](https://github.com/rowtype-yoga/purescript-unique/compare) or [opening an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new?labels=documentation).
21+
22+Sharing resources
23+-----------------
24+If you have created a tutorial, auxiliary library, interesting code example, or other resource related to Unique, please [share it with the PureScript community](https://discourse.purescript.org). Increasing awareness will bring more users (and potential contributors) to the project.
25+
26+Submitting code
27+---------------
28+Pull requests are welcome, but we ask that you [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues/new) to discuss your plans before making any significant investment of your valuable time.
29+
30+### Development environment
31+
32+You can use [Nix](https://github.com/NixOS/nix) to create a development environment with all required tooling. Simply run `nix-shell` in the root project directory, and you'll have everything you need to get started.
33+
34+### Making changes
35+
36+* After making any changes, run `purs-tidy format-in-place src test` to format the code.
37+* Unit test(s) should accompany each change.
38+
39+### Preparing your submission
40+
41+Please verify your changes before submitting a pull request using the following commands:
42+1. `purs-tidy check src test`, which ensures that modules in the `src` and `test` directories conform to the project's formatting standards; and
43+1. `spago -x test.dhall test`, which runs the unit tests.
44+
45+### Submitting a pull request
46+
47+When you are ready to [submit a pull request](https://github.com/rowtype-yoga/purescript-unique/compare), please make sure to include:
48+1. a brief description of the change;
49+1. a link to the related issue, if applicable; and
50+1. any design considerations you feel are important.
LICENSEnew file+22
@@ -0,0 +1,22 @@
1+MIT License
2+
3+Copyright (c) 2015-2017 mechairoi
4+Copyright (c) The University of Glasgow (Documentation)
5+
6+Permission is hereby granted, free of charge, to any person obtaining a copy
7+of this software and associated documentation files (the "Software"), to deal
8+in the Software without restriction, including without limitation the rights
9+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+copies of the Software, and to permit persons to whom the Software is
11+furnished to do so, subject to the following conditions:
12+
13+The above copyright notice and this permission notice shall be included in all
14+copies or substantial portions of the Software.
15+
16+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+SOFTWARE.
MODULE.mddeleted−48
@@ -1,48 +0,0 @@
1−# Module Documentation
2−
3−## Module Data.Unique
4−
5−#### `Uniq`
6−
7−``` purescript
8−data Uniq :: !
9−```
10−
11−
12−#### `Unique`
13−
14−``` purescript
15−newtype Unique
16−```
17−
18−
19−#### `newUnique`
20−
21−``` purescript
22−newUnique :: forall e. Eff (uniq :: Uniq | e) Unique
23−```
24−
25−
26−#### `showUnique`
27−
28−``` purescript
29−instance showUnique :: Show Unique
30−```
31−
32−
33−#### `eqUnique`
34−
35−``` purescript
36−instance eqUnique :: Eq Unique
37−```
38−
39−
40−#### `ordUnique`
41−
42−``` purescript
43−instance ordUnique :: Ord Unique
44−```
45−
46−
47−
48−
README.md+41−4
@@ -1,6 +1,43 @@
1−purescript-unique [![Build Status](https://travis-ci.org/mechairoi/purescript-unique.svg?branch=master)](https://travis-ci.org/mechairoi/purescript-unique)
2−===
1+# Unique
2+
3+[![CI](https://github.com/rowtype-yoga/purescript-unique/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-unique/actions?query=workflow%3ACI+branch%3Amaster)
4+[![Release](https://img.shields.io/github/release/rowtype-yoga/purescript-unique.svg)](https://github.com/rowtype-yoga/purescript-unique/releases)
5+[![Pursuit](https://pursuit.purescript.org/packages/purescript-unique/badge)](https://pursuit.purescript.org/packages/purescript-unique)
6+[![Maintainer: nsaunders](https://img.shields.io/badge/maintainer-nsaunders-teal.svg)](https://github.com/nsaunders)
7+
38Data.Unique for PureScript.
49
5−## Documentations
6−- [Module documentation](MODULE.md)
10+## Installation
11+
12+Install `unique` with [Spago](https://github.com/purescript/spago):
13+
14+```sh
15+spago install unique
16+```
17+
18+## Quick start
19+
20+The quick start hasn't been written yet (contributions are welcome!). The quick start covers a common, minimal use case for the library, whereas longer examples and tutorials are kept in the [docs directory](./docs).
21+
22+## Documentation
23+
24+`unique` documentation is stored in a few places:
25+
26+1. Module documentation is [published on Pursuit](https://pursuit.purescript.org/packages/purescript-unique).
27+2. Written documentation is kept in the [docs directory](./docs).
28+3. Usage examples can be found in [the test suite](./test).
29+
30+If you get stuck, there are several ways to get help:
31+
32+- [Open an issue](https://github.com/rowtype-yoga/purescript-unique/issues) if you have encountered a bug or problem.
33+- Ask general questions on the [PureScript Discourse](https://discourse.purescript.org) forum or the [PureScript Discord](https://discord.com/invite/sMqwYUbvz6) chat.
34+
35+## Contributing
36+
37+You can contribute to `unique` in several ways:
38+
39+1. If you encounter a problem or have a question, please [open an issue](https://github.com/rowtype-yoga/purescript-unique/issues). We'll do our best to work with you to resolve or answer it.
40+
41+2. If you would like to contribute code, tests, or documentation, please [read the contributor guide](./CONTRIBUTING.md). It's a short, helpful introduction to contributing to this library, including development instructions.
42+
43+3. If you have written a library, tutorial, guide, or other resource based on this package, please share it on the [PureScript Discourse](https://discourse.purescript.org)! Writing libraries and learning resources are a great way to help this library succeed.
bower.json+14−9
@@ -1,23 +1,28 @@
11{
22 "name": "purescript-unique",
3− "version": "0.0.1",
43 "homepage": "https://github.com/mechairoi/purescript-unique",
5− "authors": [
6− "mechairoi <ttsujikawa@gmail.com>"
7− ],
8− "keywords": [
9− "purescript"
10− ],
4+ "description": "Data.Unique for PureScript",
115 "license": "MIT",
6+ "repository": {
7+ "type": "git",
8+ "url": "git://github.com/mechairoi/purescript-unique.git"
9+ },
1210 "ignore": [
1311 "**/.*",
14− "node_modules",
1512 "bower_components",
13+ "node_modules",
14+ "output",
1615 "test",
17− "tests"
16+ "bower.json",
17+ "package.json"
1818 ],
1919 "dependencies": {
20+ "purescript-prelude": "^6.0.0",
21+ "purescript-effect": "^4.0.0",
22+ "purescript-refs": "^6.0.0"
2023 },
2124 "devDependencies": {
25+ "purescript-console": "^6.0.0",
26+ "purescript-assert": "^6.0.0"
2227 }
2328}
docs/README.mdnew file+3
@@ -0,0 +1,3 @@
1+# Unique Documentation
2+
3+This directory contains documentation for `unique`. If you are interested in contributing new documentation, please read the [contributor guidelines](../CONTRIBUTING.md) and [What Nobody Tells You About Documentation](https://documentation.divio.com) for help getting started.
gulpfile.jsdeleted−52
@@ -1,52 +0,0 @@
1−'use strict';
2−
3−var gulp = require('gulp')
4− , run = require('gulp-run')
5− , purescript = require('gulp-purescript')
6− ;
7−
8−var paths = {
9− src: 'src/**/*.purs',
10− doc: 'MODULE.md',
11− docSrc: ['src/**/*.purs', '!src/**/Internal/**/*.purs' ],
12− bowerSrc: 'bower_components/purescript-*/src/**/*.purs',
13− dest: 'output',
14− example: 'examples/*.purs',
15− test: 'test/**/*.purs'
16−};
17−
18−gulp.task('make', function() {
19− return gulp.src([paths.src].concat(paths.bowerSrc))
20− .pipe(purescript.pscMake({}))
21− .pipe(gulp.dest(paths.dest));
22−});
23−
24−gulp.task('test-make', function() {
25− return gulp.src([paths.src, paths.test].concat(paths.bowerSrc))
26− .pipe(purescript.pscMake({}))
27− .pipe(gulp.dest(paths.dest));
28−});
29−
30−gulp.task('test', ['test-make'], function() {
31− var env = {};
32− for (var e in process.env) env[e] = process.env[e];
33− env.NODE_PATH = 'output';
34− run('node -e "require(\'Test.Main\').main();"', { 'env': env }).exec();
35−});
36−
37−gulp.task('docs', function() {
38− return gulp.src(paths.docSrc)
39− .pipe(purescript.pscDocs())
40− .pipe(gulp.dest(paths.doc));
41−});
42−
43−gulp.task('psci', function() {
44− return gulp.src([paths.src, paths.test, paths.example].concat(paths.bowerSrc))
45− .pipe(purescript.dotPsci());
46−});
47−
48−gulp.task('watch', function() {
49− gulp.watch(paths.src, ['make', 'docs']);
50−});
51−
52−gulp.task('default', ['make', 'docs']);
package.json+8−12
@@ -1,18 +1,14 @@
11{
2− "name": "purescript-unique",
3− "version": "0.0.1",
4− "description": "Data.Unique for PureScript",
5− "dependencies": {
6− "gulp-run": "^1.6.7"
7− },
2+ "private": true,
83 "devDependencies": {
9− "gulp": "^3.8.10",
10− "gulp-purescript": "^0.3.1",
11− "vinyl-source-stream": "^1.0.0"
4+ "eslint": "^3.19.0",
5+ "pulp": "^11.0.0",
6+ "purescript-psa": "^0.5.1",
7+ "rimraf": "^2.6.1"
128 },
139 "scripts": {
14− "test": "gulp test",
15− "make": "gulp make",
16− "watch": "gulp watch"
10+ "clean": "rimraf output && rimraf .pulp-cache",
11+ "build": "eslint src && pulp build -- --censor-lib --strict",
12+ "test": "pulp test"
1713 }
1814}
packages.dhallnew file+5
@@ -0,0 +1,5 @@
1+let upstream =
2+ https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20230105/packages.dhall
3+ sha256:3e9fbc9ba03e9a1fcfd895f65e2d50ee2f5e86c4cd273f3d5c841b655a0e1bda
4+
5+in upstream
purs.jsonnew file+22
@@ -0,0 +1,22 @@
1+{
2+ "name": "unique",
3+ "owners": [
4+ {
5+ "email": "nick@saunde.rs",
6+ "keytype": "ssh-ed25519",
7+ "public": "AAAAC3NzaC1lZDI1NTE5AAAAIONVUgzC6fBZMCob5Ua0BShtF9QlriJV1IyZVvr8m8Gd"
8+ }
9+ ],
10+ "version": "0.6.1",
11+ "license": "MIT",
12+ "location": {
13+ "githubOwner": "nsaunders",
14+ "githubRepo": "purescript-unique"
15+ },
16+ "description": "Data.Unique for PureScript",
17+ "dependencies": {
18+ "prelude": ">=6.0.0 <7.0.0",
19+ "effect": ">=4.0.0 <5.0.0",
20+ "refs": ">=6.0.0 <7.0.0"
21+ }
22+}
shell.nixnew file+28
@@ -0,0 +1,28 @@
1+let
2+ pkgs = import (builtins.fetchTarball {
3+ url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz";
4+ }) {};
5+
6+ # To update to a newer version of easy-purescript-nix:
7+ # 1. Obtain the commit hash <rev> via `curl https://api.github.com/repos/justinwoo/easy-purescript-nix/commits/master`.
8+ # 2. Obtain the sha256 hash <sha256> via `nix-prefetch-url --unpack https://github.com/justinwoo/easy-purescript-nix/archive/<rev>.tar.gz`.
9+ # 3. Update the <rev> and <sha256> below.
10+ pursPkgs = import (pkgs.fetchFromGitHub {
11+ owner = "justinwoo";
12+ repo = "easy-purescript-nix";
13+ rev = "ee51a6d459b8fecfcb10f24ca9728e649c6a9e00";
14+ sha256 = "1w4k6mcayyg6388na0cca5qx94sm99xn3na26x2w34jlyz3bwl3m";
15+ }) {inherit pkgs;};
16+in
17+ pkgs.stdenv.mkDerivation {
18+ name = "unique";
19+ buildInputs = with pursPkgs; [
20+ purs
21+ spago
22+ pulp
23+ purs-tidy
24+
25+ pkgs.nodejs-16_x
26+ pkgs.nodePackages.bower
27+ ];
28+ }
spago.dhallnew file+5
@@ -0,0 +1,5 @@
1+{ name = "unique"
2+, dependencies = [ "effect", "prelude", "refs" ]
3+, packages = ./packages.dhall
4+, sources = [ "src/**/*.purs" ]
5+}
src/Data/Unique.jsnew file+29
@@ -0,0 +1,29 @@
1+export var zero = BigInt("0");
2+
3+var one = BigInt("1");
4+
5+export function eqImpl(a) {
6+ return function(b) {
7+ return a === b;
8+ };
9+}
10+
11+export function ordImpl(lt) {
12+ return function (eq) {
13+ return function (gt) {
14+ return function (x) {
15+ return function (y) {
16+ return x < y ? lt : x === y ? eq : gt;
17+ };
18+ };
19+ };
20+ };
21+}
22+
23+export function addOne(x) {
24+ return x + one;
25+}
26+
27+export function hashUnique(x) {
28+ return parseInt(BigInt.asIntN(32, x));
29+}
src/Data/Unique.purs+41−44
@@ -1,44 +1,41 @@
1−module Data.Unique
2− ( newUnique
3− , Unique()
4− , Uniq()
5− ) where
6−
7−import Control.Monad.Eff
8−
9−foreign import data Uniq :: !
10−
11−newtype Unique = Unique String
12−
13−foreign import newUnique """
14− var newUnique = (function() {
15− var MAX_SAFE_INTEGER = 9007199254740991;
16− var uniqueSource = [];
17− function iter(i) {
18− if(uniqueSource.length === i) {
19− for(var j = 0; j < i; ++j) uniqueSource[j] = 0;
20− uniqueSource[i] = 1;
21− } else {
22− if(uniqueSource[i] === MAX_SAFE_INTEGER) {
23− uniqueSource[i] = 0;
24− iter(i + 1);
25− } else {
26− uniqueSource[i]++;
27− }
28− }
29− };
30− return function() {
31− iter(0);
32− return uniqueSource.length === 1 ? (uniqueSource[0] + "") : uniqueSource.join(',');
33− };
34− })();""" :: forall e. Eff (uniq :: Uniq | e) Unique
35−
36−instance showUnique :: Show Unique where
37− show (Unique a) = a
38−
39−instance eqUnique :: Eq Unique where
40− (==) (Unique a) (Unique b) = a == b
41− (/=) (Unique a) (Unique b) = a /= b
42−
43−instance ordUnique :: Ord Unique where
44− compare (Unique a) (Unique b) = compare a b
1+module Data.Unique (Unique, hashUnique, newUnique) where
2+
3+import Prelude hiding (zero)
4+
5+import Effect (Effect)
6+import Effect.Ref (Ref)
7+import Effect.Ref as Ref
8+import Effect.Unsafe (unsafePerformEffect)
9+
10+-- | An abstract unique object. Objects of type `Unique` may be compared for
11+-- | equality and ordering and hashed into `Int`.
12+foreign import data Unique :: Type
13+
14+foreign import eqImpl :: Unique -> Unique -> Boolean
15+
16+instance Eq Unique where
17+ eq = eqImpl
18+
19+foreign import ordImpl :: Ordering -> Ordering -> Ordering -> Unique -> Unique -> Ordering
20+
21+instance Ord Unique where
22+ compare = ordImpl LT EQ GT
23+
24+foreign import addOne :: Unique -> Unique
25+
26+foreign import zero :: Unique
27+
28+-- | Hashes a `Unique` into an `Int`. Two `Unique`s may hash to the same value,
29+-- | although in practice this is unlikely. The `Int` returned makes a good hash
30+-- | key.
31+foreign import hashUnique :: Unique -> Int
32+
33+uniqSource :: Ref Unique
34+uniqSource = unsafePerformEffect (Ref.new zero)
35+
36+-- | Creates a new object of type `Unique`. The value returned will not compare
37+-- | equal to any other value of type `Unique` returned by previous calls to
38+-- | `newUnique`. There is no limit on the number of times `newUnique` may be
39+-- | called.
40+newUnique :: Effect Unique
41+newUnique = Ref.modify addOne uniqSource
test.dhallnew file+6
@@ -0,0 +1,6 @@
1+let conf = ./spago.dhall
2+
3+in conf // {
4+ sources = conf.sources # ["test/**/*.purs"],
5+ dependencies = conf.dependencies # ["assert", "console"]
6+}
test/Main.pursnew file+17
@@ -0,0 +1,17 @@
1+module Test.Main where
2+
3+import Prelude
4+import Data.Unique (hashUnique, newUnique)
5+import Test.Assert (assert)
6+import Effect (Effect)
7+import Effect.Console (log)
8+
9+main :: Effect Unit
10+main = do
11+ log "Test Data.Unique"
12+ a <- newUnique
13+ b <- newUnique
14+ assert $ a == a
15+ assert $ a < b
16+ assert $ hashUnique a == hashUnique a
17+ assert $ hashUnique a /= hashUnique b