From df17016283211c2364d2b834c7b685b7330a452c Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Thu, 15 Oct 2026 00:51:16 +0000 Subject: [PATCH 1/6] Migrate to Spago and update CI --- .github/workflows/ci.yml | 28 ++++++++++++---------------- .gitignore | 6 +++--- .tidyrc.json | 10 ++++++++++ CHANGELOG.md | 10 +++------- bower.json | 37 ------------------------------------- package.json | 15 ++++++++------- spago.yaml | 39 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 75 insertions(+), 70 deletions(-) create mode 100644 .tidyrc.json delete mode 100644 bower.json create mode 100644 spago.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c69237a..a4f213f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,30 +6,26 @@ on: pull_request: branches: [master] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - - uses: purescript-contrib/setup-purescript@main + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 with: - purescript: "unstable" - - - uses: actions/setup-node@v2 - with: - node-version: "14.x" + node-version: "24" - name: Install dependencies - run: | - npm install -g bower - npm install - bower install --production + run: npm install - name: Build source - run: npm run-script build + run: npm run build - name: Run tests - run: | - bower install - npm run-script test --if-present + run: npm test + + - name: Check formatting + run: npm run format:check diff --git a/.gitignore b/.gitignore index 7224331..630673a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ /.* !/.gitignore -!/.eslintrc.json +!/.tidyrc.json !/.github/ -package-lock.json -/bower_components/ +/package-lock.json +/spago.lock /node_modules/ /output/ diff --git a/.tidyrc.json b/.tidyrc.json new file mode 100644 index 0000000..9e39cf1 --- /dev/null +++ b/.tidyrc.json @@ -0,0 +1,10 @@ +{ + "importSort": "ide", + "importWrap": "source", + "indent": 2, + "operatorsFile": null, + "ribbon": 1, + "typeArrowPlacement": "first", + "unicode": "never", + "width": null +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 39ace0b..3785a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,12 @@ Notable changes to this project 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). -## [Unreleased] - -Breaking changes: - -New features: - -Bugfixes: +## [v4.0.1](https://github.com/purescript/purescript-gen/releases/tag/v4.0.1) Other improvements: +- Migrate from Bower/Pulp to Spago and update CI + ## [v4.0.0](https://github.com/purescript/purescript-gen/releases/tag/v4.0.0) - 2022-04-27 Breaking changes: diff --git a/bower.json b/bower.json deleted file mode 100644 index 8392bc5..0000000 --- a/bower.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "purescript-gen", - "homepage": "https://github.com/purescript/purescript-gen", - "license": "BSD-3-Clause", - "repository": { - "type": "git", - "url": "https://github.com/purescript/purescript-gen.git" - }, - "ignore": [ - "**/.*", - "bower_components", - "node_modules", - "output", - "test", - "bower.json", - "package.json" - ], - "dependencies": { - "purescript-either": "^6.0.0", - "purescript-foldable-traversable": "^6.0.0", - "purescript-identity": "^6.0.0", - "purescript-maybe": "^6.0.0", - "purescript-newtype": "^5.0.0", - "purescript-nonempty": "^7.0.0", - "purescript-prelude": "^6.0.0", - "purescript-tailrec": "^6.0.0", - "purescript-tuples": "^7.0.0", - "purescript-unfoldable": "^6.0.0" - }, - "devDependencies": { - "purescript-arrays": "^7.0.0", - "purescript-assert": "^6.0.0", - "purescript-console": "^6.0.0", - "purescript-lcg": "^4.0.0", - "purescript-transformers": "^6.0.0" - } -} diff --git a/package.json b/package.json index 30a6ad0..e5eb282 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,15 @@ { "private": true, "scripts": { - "clean": "rimraf output && rimraf .pulp-cache", - "build": "pulp build -- --censor-lib --strict", - "test": "pulp test" + "build": "spago build", + "test": "spago test", + "format": "purs-tidy format-in-place src test && oxfmt --write .", + "format:check": "purs-tidy check src test && oxfmt --check ." }, "devDependencies": { - "eslint": "^7.15.0", - "pulp": "16.0.0-0", - "purescript-psa": "^0.8.2", - "rimraf": "^3.0.2" + "oxfmt": "^0.73.0", + "purescript": "^0.15.16", + "purs-tidy": "^0.11.1", + "spago": "^1.0.5" } } diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..768c6a3 --- /dev/null +++ b/spago.yaml @@ -0,0 +1,39 @@ +package: + name: gen + description: A type class for random generator implementations. + build: + strict: true + pedanticPackages: true + publish: + version: 4.0.1 + license: BSD-3-Clause + location: + githubOwner: purescript + githubRepo: purescript-gen + dependencies: + - either: ">=6.0.0 <7.0.0" + - foldable-traversable: ">=6.0.0 <7.0.0" + - identity: ">=6.0.0 <7.0.0" + - maybe: ">=6.0.0 <7.0.0" + - newtype: ">=5.0.0 <6.0.0" + - nonempty: ">=7.0.0 <8.0.0" + - prelude: ">=6.0.0 <7.0.0" + - tailrec: ">=6.0.0 <7.0.0" + - tuples: ">=7.0.0 <8.0.0" + - unfoldable: ">=6.0.0 <7.0.0" + test: + main: Test.Main + strict: true + pedanticPackages: true + dependencies: + - arrays: ">=7.0.0 <8.0.0" + - assert: ">=6.0.0 <7.0.0" + - bifunctors: ">=6.0.0 <7.0.0" + - console: ">=6.0.0 <7.0.0" + - effect: ">=4.0.0 <5.0.0" + - integers: ">=6.0.0 <7.0.0" + - lcg: ">=4.0.0 <5.0.0" + - numbers: ">=9.0.0 <10.0.0" + - partial: ">=4.0.0 <5.0.0" + - transformers: ">=6.0.0 <7.0.0" +workspace: {} From 087ff6d59700a2e0061b8a58ade86a998c427162 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Thu, 15 Oct 2026 00:51:32 +0000 Subject: [PATCH 2/6] Format PureScript sources and repository files --- CHANGELOG.md | 4 ++++ src/Control/Monad/Gen.purs | 22 ++++++++++++---------- test/Frequency.purs | 23 ++++++++++++----------- test/Main.purs | 16 ++++++++-------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3785a9d..bc15817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Other improvements: ## [v4.0.0](https://github.com/purescript/purescript-gen/releases/tag/v4.0.0) - 2022-04-27 Breaking changes: + - Update project and deps to PureScript v0.15.0 (#35 by @JordanMartinez) New features: @@ -22,15 +23,18 @@ Other improvements: ## [v3.0.0](https://github.com/purescript/purescript-gen/releases/tag/v3.0.0) - 2021-02-26 Breaking changes: + - Added support for PureScript 0.14 and dropped support for all previous versions (#26) New features: Bugfixes: + - Make `elements` test no longer hang at cost of possible false negative (#29) - Fixed `fromIndex` internal helper in tests (#23) Other improvements: + - Refer people to the `quickcheck` package's `Gen` type as a default implementation for `MonadGen` (#25) - Restored frequency tests (#28) - Migrated CI to GitHub Actions and updated installation instructions to use Spago (#30) diff --git a/src/Control/Monad/Gen.purs b/src/Control/Monad/Gen.purs index 3ceee57..f7c1991 100644 --- a/src/Control/Monad/Gen.purs +++ b/src/Control/Monad/Gen.purs @@ -41,9 +41,8 @@ newtype FreqSemigroup a = FreqSemigroup (Number -> Tuple (Maybe Number) a) freqSemigroup :: forall a. Tuple Number a -> FreqSemigroup a freqSemigroup (Tuple weight x) = FreqSemigroup \pos -> - if pos >= weight - then Tuple (Just (pos - weight)) x - else Tuple Nothing x + if pos >= weight then Tuple (Just (pos - weight)) x + else Tuple Nothing x getFreqVal :: forall a. FreqSemigroup a -> Number -> a getFreqVal (FreqSemigroup f) = snd <<< f @@ -66,8 +65,10 @@ frequency => f (Tuple Number (m a)) -> m a frequency xs = - let total = alaF Additive foldMap fst xs - in chooseFloat 0.0 total >>= getFreqVal (foldMap1 freqSemigroup xs) + let + total = alaF Additive foldMap fst xs + in + chooseFloat 0.0 total >>= getFreqVal (foldMap1 freqSemigroup xs) -- | Creates a generator that outputs a value chosen from a selection with -- | uniform probability. @@ -98,6 +99,7 @@ unfoldable gen = unfoldr unfold <$> sized (tailRecM loopGen <<< Tuple Nil) | otherwise = do x <- gen pure $ Loop (Tuple (Cons x acc) (n - 1)) + unfold :: LL a -> Maybe (Tuple a (LL a)) unfold = case _ of Nil -> Nothing @@ -125,8 +127,8 @@ filtered gen = tailRecM go unit fromIndex :: forall f a. Foldable1 f => Int -> f a -> a fromIndex i xs = go i (foldr Cons Nil xs) where - go _ (Cons a Nil) = a - go j (Cons a _) | j <= 0 = a - go j (Cons _ as) = go (j - 1) as - -- next case is "impossible", but serves as proof of non-emptyness - go _ Nil = un Last (foldMap1 Last xs) + go _ (Cons a Nil) = a + go j (Cons a _) | j <= 0 = a + go j (Cons _ as) = go (j - 1) as + -- next case is "impossible", but serves as proof of non-emptyness + go _ Nil = un Last (foldMap1 Last xs) diff --git a/test/Frequency.purs b/test/Frequency.purs index b52c144..07c738a 100644 --- a/test/Frequency.purs +++ b/test/Frequency.purs @@ -3,11 +3,11 @@ module Test.Frequency where import Prelude import Control.Monad.Gen (class MonadGen, frequency) -import Control.Monad.State (State, class MonadState, get, put, evalStateT) -import Data.Array (replicate, groupAll, length) +import Control.Monad.State (class MonadState, State, evalStateT, get, put) +import Data.Array (groupAll, length, replicate) import Data.Array.NonEmpty (toNonEmpty) import Data.Newtype (unwrap) -import Data.NonEmpty ((:|), NonEmpty(..)) +import Data.NonEmpty (NonEmpty(..), (:|)) import Data.Number (remainder) import Data.Traversable (sequence) import Data.Tuple (Tuple(..)) @@ -16,6 +16,7 @@ import Partial.Unsafe (unsafeCrashWith) import Test.Assert (assert) newtype TestGenFrequency a = TestGenFrequency (State Number a) + derive newtype instance testGenFunctor :: Functor TestGenFrequency derive newtype instance testGenApply :: Apply TestGenFrequency derive newtype instance testGenBind :: Bind TestGenFrequency @@ -42,14 +43,14 @@ check = abcGen :: TestGenFrequency String abcGen = frequency $ - ( Tuple 10.0 $ pure "A" ) :| - [ Tuple 20.0 $ pure "B" - , Tuple 0.0 $ pure "Z" - , Tuple 30.0 $ pure "C" - , Tuple 40.0 $ pure "D" - , Tuple 50.0 $ pure "E" - , Tuple 50.0 $ pure "F" - ] + (Tuple 10.0 $ pure "A") :| + [ Tuple 20.0 $ pure "B" + , Tuple 0.0 $ pure "Z" + , Tuple 30.0 $ pure "C" + , Tuple 40.0 $ pure "D" + , Tuple 50.0 $ pure "E" + , Tuple 50.0 $ pure "F" + ] abcArrGen = sequence $ replicate 200 abcGen abcArr = runTestGenFrequency abcArrGen `evalStateT` 0.0 # unwrap actual = groupAll abcArr <#> \nea -> case toNonEmpty nea of diff --git a/test/Main.purs b/test/Main.purs index 66f21cf..11276d8 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -7,8 +7,8 @@ import Control.Monad.Gen.Common as GenC import Control.Monad.Rec.Class (class MonadRec, tailRecM) import Data.Array as Array import Data.Bifunctor (bimap) -import Data.Int as Int import Data.Foldable (foldl) +import Data.Int as Int import Data.NonEmpty (NonEmpty, (:|)) import Data.Tuple (Tuple(..), snd) import Effect (Effect) @@ -21,22 +21,22 @@ import Test.Frequency as Frequency main :: Effect Unit main = do - seed ← LCG.randomSeed + seed <- LCG.randomSeed runTestGen seed do log $ show seed log "`unfoldable` should not loop on negative size" - nil :: Array Unit ← Gen.resize (const (-1)) $ Gen.unfoldable (pure unit) + nil :: Array Unit <- Gen.resize (const (-1)) $ Gen.unfoldable (pure unit) liftEffect $ assertEqual { actual: nil, expected: [] } log "`genNonEmpty` should not reduce the remainder size below zero" - one :: NonEmpty Array Int ← Gen.resize (const 0) $ GenC.genNonEmpty (Gen.sized pure) + one :: NonEmpty Array Int <- Gen.resize (const 0) $ GenC.genNonEmpty (Gen.sized pure) liftEffect $ assertEqual { actual: one, expected: 0 :| [] } log "Ensure that `elements` will produce all possible values (low chance of false negative)" - let testElems = "A" :| ["B", "C", "D"] + let testElems = "A" :| [ "B", "C", "D" ] -- use `resize` to generate an Array of 1,000 elements -- to reduce the chance of a false positive. @@ -79,9 +79,9 @@ instance monadTestGen :: Monad TestGen instance monadRecTestGen :: MonadRec TestGen where tailRecM f a = TestGen (tailRecM go <<< flip Tuple a) where - go (Tuple s a') = - unTestGen (f a') s >>= \(Tuple s' m) -> - pure $ bimap (Tuple s') (Tuple s') m + go (Tuple s a') = + unTestGen (f a') s >>= \(Tuple s' m) -> + pure $ bimap (Tuple s') (Tuple s') m instance monadGenTestGen :: Gen.MonadGen TestGen where chooseInt a b = Int.round <$> Gen.chooseFloat (Int.toNumber a) (Int.toNumber b) From 12adc0d716a2917241712ee4876e7d8e003e1b8d Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Thu, 15 Oct 2026 00:53:04 +0000 Subject: [PATCH 3/6] Credit migration pull request in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc15817..bf61150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Notable changes to this project are documented in this file. The format is based Other improvements: -- Migrate from Bower/Pulp to Spago and update CI +- Migrate from Bower/Pulp to Spago and update CI (#37 by @thomashoneyman) ## [v4.0.0](https://github.com/purescript/purescript-gen/releases/tag/v4.0.0) - 2022-04-27 From 3b824535bf0f3cdb7d80e71e30e5c3fa45463c05 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Thu, 15 Oct 2026 21:26:11 +0000 Subject: [PATCH 4/6] Prepare changelog release date and unreleased section --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf61150..ee3e1e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,17 @@ Notable changes to this project 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). -## [v4.0.1](https://github.com/purescript/purescript-gen/releases/tag/v4.0.1) +## [Unreleased] + +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v4.0.1](https://github.com/purescript/purescript-gen/releases/tag/v4.0.1) - 2026-10-17 Other improvements: From e78a1bf6278877fa266c95092c9eb5eaf52d9ecd Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sat, 17 Oct 2026 13:02:36 +0000 Subject: [PATCH 5/6] Apply approved PureScript layout improvements --- src/Control/Monad/Gen.purs | 37 +++++++++++++++++++------------------ test/Frequency.purs | 5 ++--- test/Main.purs | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Control/Monad/Gen.purs b/src/Control/Monad/Gen.purs index f7c1991..5065745 100644 --- a/src/Control/Monad/Gen.purs +++ b/src/Control/Monad/Gen.purs @@ -41,8 +41,10 @@ newtype FreqSemigroup a = FreqSemigroup (Number -> Tuple (Maybe Number) a) freqSemigroup :: forall a. Tuple Number a -> FreqSemigroup a freqSemigroup (Tuple weight x) = FreqSemigroup \pos -> - if pos >= weight then Tuple (Just (pos - weight)) x - else Tuple Nothing x + if pos >= weight then + Tuple (Just (pos - weight)) x + else + Tuple Nothing x getFreqVal :: forall a. FreqSemigroup a -> Number -> a getFreqVal (FreqSemigroup f) = snd <<< f @@ -64,11 +66,9 @@ frequency => Foldable1 f => f (Tuple Number (m a)) -> m a -frequency xs = - let - total = alaF Additive foldMap fst xs - in - chooseFloat 0.0 total >>= getFreqVal (foldMap1 freqSemigroup xs) +frequency xs = do + let total = alaF Additive foldMap fst xs + chooseFloat 0.0 total >>= getFreqVal (foldMap1 freqSemigroup xs) -- | Creates a generator that outputs a value chosen from a selection with -- | uniform probability. @@ -93,12 +93,12 @@ unfoldable unfoldable gen = unfoldr unfold <$> sized (tailRecM loopGen <<< Tuple Nil) where loopGen :: Tuple (LL a) Int -> m (Step (Tuple (LL a) Int) (LL a)) - loopGen (Tuple acc n) - | n <= 0 = - pure $ Done acc - | otherwise = do - x <- gen - pure $ Loop (Tuple (Cons x acc) (n - 1)) + loopGen (Tuple acc n) = + if n <= 0 then + pure $ Done acc + else do + x <- gen + pure $ Loop (Tuple (Cons x acc) (n - 1)) unfold :: LL a -> Maybe (Tuple a (LL a)) unfold = case _ of @@ -127,8 +127,9 @@ filtered gen = tailRecM go unit fromIndex :: forall f a. Foldable1 f => Int -> f a -> a fromIndex i xs = go i (foldr Cons Nil xs) where - go _ (Cons a Nil) = a - go j (Cons a _) | j <= 0 = a - go j (Cons _ as) = go (j - 1) as - -- next case is "impossible", but serves as proof of non-emptyness - go _ Nil = un Last (foldMap1 Last xs) + go j = case _ of + Cons a Nil -> a + Cons a _ | j <= 0 -> a + Cons _ as -> go (j - 1) as + -- next case is "impossible", but serves as proof of non-emptyness + Nil -> un Last (foldMap1 Last xs) diff --git a/test/Frequency.purs b/test/Frequency.purs index 07c738a..0538fa4 100644 --- a/test/Frequency.purs +++ b/test/Frequency.purs @@ -38,7 +38,7 @@ runTestGenFrequency :: TestGenFrequency ~> State Number runTestGenFrequency (TestGenFrequency x) = x check :: Effect Unit -check = +check = do let abcGen :: TestGenFrequency String abcGen = @@ -63,5 +63,4 @@ check = , (Tuple 50 "E") , (Tuple 50 "F") ] - in - assert (expected == actual) + assert (expected == actual) diff --git a/test/Main.purs b/test/Main.purs index 11276d8..a7dd9ef 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -99,7 +99,7 @@ lcgStep = pure $ Tuple (Tuple (LCG.lcgNext seed) size) (LCG.unSeed seed) uniform :: TestGen Number -uniform = lcgStep <#> (\n -> Int.toNumber n / Int.toNumber LCG.lcgM) +uniform = lcgStep <#> \n -> Int.toNumber n / Int.toNumber LCG.lcgM unTestGen :: forall a. TestGen a -> GenState -> Effect (Tuple GenState a) unTestGen (TestGen k) = k From 02d56fd309e18de690bfd0f70a8e0b61bf4eb0c5 Mon Sep 17 00:00:00 2001 From: Thomas Honeyman Date: Sat, 17 Oct 2026 16:21:10 +0000 Subject: [PATCH 6/6] Link Unreleased changelog comparison --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee3e1e1..ad28b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ Notable changes to this project 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). -## [Unreleased] +## [Unreleased](https://github.com/purescript/purescript-gen/compare/v4.0.1...HEAD) Breaking changes: