From 0a68e5bf416cf61bb2e2d2ea377c1518701be306 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 13:20:44 -0500 Subject: [PATCH 01/10] Add purs-tidy --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa57eb55..6721e67a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,7 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: purescript: "unstable" + purs-tidy: "stable" - uses: actions/setup-node@v1 with: @@ -32,3 +33,7 @@ jobs: run: | bower install npm run-script test --if-present + + + - name: Check formatting + run: purs-tidy check src test \ No newline at end of file From f518fe09d0c13325c5069de244253b4492986ef5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 13:20:45 -0500 Subject: [PATCH 02/10] Formatted code via purs-tidy --- src/Control/Applicative.purs | 8 ++++-- src/Control/Apply.purs | 15 +++++++--- src/Control/Category.purs | 3 +- src/Control/Monad.purs | 2 +- src/Data/EuclideanRing.purs | 16 ++++++----- src/Data/Function.purs | 8 ++++-- src/Data/Functor.purs | 16 +++++++---- src/Data/Ordering.purs | 2 +- src/Data/Semiring/Generic.purs | 6 ++-- src/Data/Show.purs | 5 ++-- src/Data/Show/Generic.purs | 28 +++++++++++-------- test/Data/Generic/Rep.purs | 50 ++++++++++++++++++++++++++-------- 12 files changed, 105 insertions(+), 54 deletions(-) diff --git a/src/Control/Applicative.purs b/src/Control/Applicative.purs index da24dd45..6d444460 100644 --- a/src/Control/Applicative.purs +++ b/src/Control/Applicative.purs @@ -1,7 +1,9 @@ module Control.Applicative - ( class Applicative, pure + ( class Applicative + , pure , liftA1 - , unless, when + , unless + , when , module Control.Apply , module Data.Functor ) where @@ -37,7 +39,7 @@ instance applicativeFn :: Applicative ((->) r) where pure x _ = x instance applicativeArray :: Applicative Array where - pure x = [x] + pure x = [ x ] instance applicativeProxy :: Applicative Proxy where pure _ = Proxy diff --git a/src/Control/Apply.purs b/src/Control/Apply.purs index 0cc90dd8..6cde1c85 100644 --- a/src/Control/Apply.purs +++ b/src/Control/Apply.purs @@ -1,8 +1,15 @@ module Control.Apply - ( class Apply, apply, (<*>) - , applyFirst, (<*) - , applySecond, (*>) - , lift2, lift3, lift4, lift5 + ( class Apply + , apply + , (<*>) + , applyFirst + , (<*) + , applySecond + , (*>) + , lift2 + , lift3 + , lift4 + , lift5 , module Data.Functor ) where diff --git a/src/Control/Category.purs b/src/Control/Category.purs index 78625925..c2f224a4 100644 --- a/src/Control/Category.purs +++ b/src/Control/Category.purs @@ -1,5 +1,6 @@ module Control.Category - ( class Category, identity + ( class Category + , identity , module Control.Semigroupoid ) where diff --git a/src/Control/Monad.purs b/src/Control/Monad.purs index 8f3a0954..3d8400ae 100644 --- a/src/Control/Monad.purs +++ b/src/Control/Monad.purs @@ -62,7 +62,7 @@ whenM mb m = do -- | Perform a monadic action unless a condition is true, where the conditional -- | value is also in a monadic context. unlessM :: forall m. Monad m => m Boolean -> m Unit -> m Unit -unlessM mb m = do +unlessM mb m = do b <- mb unless b m diff --git a/src/Data/EuclideanRing.purs b/src/Data/EuclideanRing.purs index 3f790bfe..b2ddbfaa 100644 --- a/src/Data/EuclideanRing.purs +++ b/src/Data/EuclideanRing.purs @@ -1,5 +1,9 @@ module Data.EuclideanRing - ( class EuclideanRing, degree, div, mod, (/) + ( class EuclideanRing + , degree + , div + , mod + , (/) , gcd , lcm , module Data.CommutativeRing @@ -86,13 +90,11 @@ foreign import numDiv :: Number -> Number -> Number -- | The *greatest common divisor* of two values. gcd :: forall a. Eq a => EuclideanRing a => a -> a -> a gcd a b = - if b == zero - then a - else gcd b (a `mod` b) + if b == zero then a + else gcd b (a `mod` b) -- | The *least common multiple* of two values. lcm :: forall a. Eq a => EuclideanRing a => a -> a -> a lcm a b = - if a == zero || b == zero - then zero - else a * b / gcd a b + if a == zero || b == zero then zero + else a * b / gcd a b diff --git a/src/Data/Function.purs b/src/Data/Function.purs index 74cc3cc1..37ff740c 100644 --- a/src/Data/Function.purs +++ b/src/Data/Function.purs @@ -1,8 +1,10 @@ module Data.Function ( flip , const - , apply, ($) - , applyFlipped, (#) + , apply + , ($) + , applyFlipped + , (#) , applyN , on , module Control.Category @@ -103,7 +105,7 @@ applyN :: forall a. (a -> a) -> Int -> a -> a applyN f = go where go n acc - | n <= 0 = acc + | n <= 0 = acc | otherwise = go (n - 1) (f acc) -- | The `on` function is used to change the domain of a binary operator. diff --git a/src/Data/Functor.purs b/src/Data/Functor.purs index 3e18df84..fb97ea8d 100644 --- a/src/Data/Functor.purs +++ b/src/Data/Functor.purs @@ -1,10 +1,16 @@ module Data.Functor - ( class Functor, map, (<$>) - , mapFlipped, (<#>) + ( class Functor + , map + , (<$>) + , mapFlipped + , (<#>) , void - , voidRight, (<$) - , voidLeft, ($>) - , flap, (<@>) + , voidRight + , (<$) + , voidLeft + , ($>) + , flap + , (<@>) ) where import Data.Function (const, compose) diff --git a/src/Data/Ordering.purs b/src/Data/Ordering.purs index 61f0ae93..f2477cd2 100644 --- a/src/Data/Ordering.purs +++ b/src/Data/Ordering.purs @@ -16,7 +16,7 @@ instance eqOrdering :: Eq Ordering where eq LT LT = true eq GT GT = true eq EQ EQ = true - eq _ _ = false + eq _ _ = false instance semigroupOrdering :: Semigroup Ordering where append LT _ = LT diff --git a/src/Data/Semiring/Generic.purs b/src/Data/Semiring/Generic.purs index 578023e7..6bf60d17 100644 --- a/src/Data/Semiring/Generic.purs +++ b/src/Data/Semiring/Generic.purs @@ -5,10 +5,10 @@ import Prelude import Data.Generic.Rep (class Generic, Argument(..), Constructor(..), NoArguments(..), Product(..), from, to) class GenericSemiring a where - genericAdd' :: a -> a -> a + genericAdd' :: a -> a -> a genericZero' :: a - genericMul' :: a -> a -> a - genericOne' :: a + genericMul' :: a -> a -> a + genericOne' :: a instance genericSemiringNoArguments :: GenericSemiring NoArguments where genericAdd' _ _ = NoArguments diff --git a/src/Data/Show.purs b/src/Data/Show.purs index 65ae038a..dab2d858 100644 --- a/src/Data/Show.purs +++ b/src/Data/Show.purs @@ -46,10 +46,11 @@ instance showRecord :: ( Nub rs rs , RL.RowToList rs ls , ShowRecordFields ls rs - ) => Show (Record rs) where + ) => + Show (Record rs) where show record = case showRecordFields (Proxy :: Proxy ls) record of [] -> "{}" - fields -> intercalate " " ["{", intercalate ", " fields, "}"] + fields -> intercalate " " [ "{", intercalate ", " fields, "}" ] -- | A class for records where all fields have `Show` instances, used to -- | implement the `Show` instance for records. diff --git a/src/Data/Show/Generic.purs b/src/Data/Show/Generic.purs index 5a5f08fa..297986a4 100644 --- a/src/Data/Show/Generic.purs +++ b/src/Data/Show/Generic.purs @@ -27,24 +27,28 @@ instance genericShowSum :: (GenericShow a, GenericShow b) => GenericShow (Sum a genericShow' (Inl a) = genericShow' a genericShow' (Inr b) = genericShow' b -instance genericShowArgsProduct - :: (GenericShowArgs a, GenericShowArgs b) - => GenericShowArgs (Product a b) where +instance genericShowArgsProduct :: + ( GenericShowArgs a + , GenericShowArgs b + ) => + GenericShowArgs (Product a b) where genericShowArgs (Product a b) = genericShowArgs a <> genericShowArgs b -instance genericShowConstructor - :: (GenericShowArgs a, IsSymbol name) - => GenericShow (Constructor name a) where +instance genericShowConstructor :: + ( GenericShowArgs a + , IsSymbol name + ) => + GenericShow (Constructor name a) where genericShow' (Constructor a) = - case genericShowArgs a of - [] -> ctor - args -> "(" <> intercalate " " ([ctor] <> args) <> ")" + case genericShowArgs a of + [] -> ctor + args -> "(" <> intercalate " " ([ ctor ] <> args) <> ")" where - ctor :: String - ctor = reflectSymbol (Proxy :: Proxy name) + ctor :: String + ctor = reflectSymbol (Proxy :: Proxy name) instance genericShowArgsArgument :: Show a => GenericShowArgs (Argument a) where - genericShowArgs (Argument a) = [show a] + genericShowArgs (Argument a) = [ show a ] -- | A `Generic` implementation of the `show` member from the `Show` type class. genericShow :: forall a rep. Generic a rep => GenericShow rep => a -> String diff --git a/test/Data/Generic/Rep.purs b/test/Data/Generic/Rep.purs index 0f30d340..45c4c1e3 100644 --- a/test/Data/Generic/Rep.purs +++ b/test/Data/Generic/Rep.purs @@ -27,59 +27,78 @@ instance showList :: Show a => Show (List a) where show x = GShow.genericShow x data SimpleBounded = A | B | C | D + derive instance genericSimpleBounded :: G.Generic SimpleBounded _ instance eqSimpleBounded :: Eq SimpleBounded where eq x y = GEq.genericEq x y + instance ordSimpleBounded :: Ord SimpleBounded where compare x y = GOrd.genericCompare x y + instance showSimpleBounded :: Show SimpleBounded where show x = GShow.genericShow x + instance boundedSimpleBounded :: Bounded SimpleBounded where bottom = GBounded.genericBottom top = GBounded.genericTop data Option a = None | Some a + derive instance genericOption :: G.Generic (Option a) _ instance eqOption :: Eq a => Eq (Option a) where eq x y = GEq.genericEq x y + instance ordOption :: Ord a => Ord (Option a) where compare x y = GOrd.genericCompare x y + instance showOption :: Show a => Show (Option a) where show x = GShow.genericShow x + instance boundedOption :: Bounded a => Bounded (Option a) where bottom = GBounded.genericBottom top = GBounded.genericTop data Bit = Zero | One + derive instance genericBit :: G.Generic Bit _ instance eqBit :: Eq Bit where eq x y = GEq.genericEq x y + instance ordBit :: Ord Bit where compare x y = GOrd.genericCompare x y + instance showBit :: Show Bit where show x = GShow.genericShow x + instance boundedBit :: Bounded Bit where bottom = GBounded.genericBottom top = GBounded.genericTop data Pair a b = Pair a b + derive instance genericPair :: G.Generic (Pair a b) _ instance eqPair :: (Eq a, Eq b) => Eq (Pair a b) where eq = GEq.genericEq + instance ordPair :: (Ord a, Ord b) => Ord (Pair a b) where compare = GOrd.genericCompare + instance showPair :: (Show a, Show b) => Show (Pair a b) where show = GShow.genericShow + instance boundedPair :: (Bounded a, Bounded b) => Bounded (Pair a b) where bottom = GBounded.genericBottom top = GBounded.genericTop + instance semiringPair :: (Semiring a, Semiring b) => Semiring (Pair a b) where add (Pair x1 y1) (Pair x2 y2) = Pair (add x1 x2) (add y1 y2) one = Pair one one mul (Pair x1 y1) (Pair x2 y2) = Pair (mul x1 x2) (mul y1 y2) zero = Pair zero zero + instance ringPair :: (Ring a, Ring b) => Ring (Pair a b) where sub (Pair x1 y1) (Pair x2 y2) = Pair (sub x1 x2) (sub y1 y2) + instance heytingAlgebraPair :: (HeytingAlgebra a, HeytingAlgebra b) => HeytingAlgebra (Pair a b) where tt = Pair tt tt ff = Pair ff ff @@ -88,26 +107,33 @@ instance heytingAlgebraPair :: (HeytingAlgebra a, HeytingAlgebra b) => HeytingAl disj (Pair x1 y1) (Pair x2 y2) = Pair (disj x1 x2) (disj y1 y2) not (Pair x y) = Pair (not x) (not y) -data A1 = A1 (Pair (Pair Int {a :: Int}) {a :: Int}) +data A1 = A1 (Pair (Pair Int { a :: Int }) { a :: Int }) + derive instance genericA1 :: G.Generic A1 _ instance eqA1 :: Eq A1 where eq a = GEq.genericEq a + instance showA1 :: Show A1 where show a = GShow.genericShow a + instance semiringA1 :: Semiring A1 where zero = GSemiring.genericZero one = GSemiring.genericOne add x y = GSemiring.genericAdd x y mul x y = GSemiring.genericMul x y + instance ringA1 :: Ring A1 where sub x y = GRing.genericSub x y -data B1 = B1 (Pair (Pair Boolean {a :: Boolean}) {a :: Boolean}) +data B1 = B1 (Pair (Pair Boolean { a :: Boolean }) { a :: Boolean }) + derive instance genericB1 :: G.Generic B1 _ instance eqB1 :: Eq B1 where eq a = GEq.genericEq a + instance showB1 :: Show B1 where show a = GShow.genericShow a + instance heytingAlgebraB1 :: HeytingAlgebra B1 where ff = GHeytingAlgebra.genericFF tt = GHeytingAlgebra.genericTT @@ -166,31 +192,31 @@ testGenericRep = do top == (Pair One D :: Pair Bit SimpleBounded) assert "Checking zero" $ - (zero :: A1) == A1 (Pair (Pair 0 {a: 0}) {a: 0}) + (zero :: A1) == A1 (Pair (Pair 0 { a: 0 }) { a: 0 }) assert "Checking one" $ - (one :: A1) == A1 (Pair (Pair 1 {a: 1}) {a: 1}) + (one :: A1) == A1 (Pair (Pair 1 { a: 1 }) { a: 1 }) assert "Checking add" $ - A1 (Pair (Pair 100 {a: 10}) {a: 20}) + A1 (Pair (Pair 50 {a: 30}) {a: 40}) == A1 (Pair (Pair 150 {a: 40}) {a: 60}) + A1 (Pair (Pair 100 { a: 10 }) { a: 20 }) + A1 (Pair (Pair 50 { a: 30 }) { a: 40 }) == A1 (Pair (Pair 150 { a: 40 }) { a: 60 }) assert "Checking mul" $ - A1 (Pair (Pair 100 {a: 10}) {a: 20}) * A1 (Pair (Pair 50 {a: 30}) {a: 40}) == A1 (Pair (Pair 5000 {a: 300}) {a: 800}) + A1 (Pair (Pair 100 { a: 10 }) { a: 20 }) * A1 (Pair (Pair 50 { a: 30 }) { a: 40 }) == A1 (Pair (Pair 5000 { a: 300 }) { a: 800 }) assert "Checking sub" $ - A1 (Pair (Pair 100 {a: 10}) {a: 20}) - A1 (Pair (Pair 50 {a: 30}) {a: 40}) == A1 (Pair (Pair 50 {a: -20}) {a: -20}) + A1 (Pair (Pair 100 { a: 10 }) { a: 20 }) - A1 (Pair (Pair 50 { a: 30 }) { a: 40 }) == A1 (Pair (Pair 50 { a: -20 }) { a: -20 }) assert "Checking ff" $ - (ff :: B1) == B1 (Pair (Pair false {a: false}) {a: false}) + (ff :: B1) == B1 (Pair (Pair false { a: false }) { a: false }) assert "Checking tt" $ - (tt :: B1) == B1 (Pair (Pair true {a: true}) {a: true}) + (tt :: B1) == B1 (Pair (Pair true { a: true }) { a: true }) assert "Checking conj" $ - (B1 (Pair (Pair true {a: false}) {a: true}) && B1 (Pair (Pair false {a: false}) {a: true})) == B1 (Pair (Pair false { a: false }) { a: true }) + (B1 (Pair (Pair true { a: false }) { a: true }) && B1 (Pair (Pair false { a: false }) { a: true })) == B1 (Pair (Pair false { a: false }) { a: true }) assert "Checking disj" $ - (B1 (Pair (Pair true {a: false}) {a: true}) || B1 (Pair (Pair false {a: false}) {a: true})) == B1 (Pair (Pair true { a: false }) { a: true }) + (B1 (Pair (Pair true { a: false }) { a: true }) || B1 (Pair (Pair false { a: false }) { a: true })) == B1 (Pair (Pair true { a: false }) { a: true }) assert "Checking not" $ - not B1 (Pair (Pair true {a: false}) {a: true}) == B1 (Pair (Pair false {a: true}) {a: false}) + not B1 (Pair (Pair true { a: false }) { a: true }) == B1 (Pair (Pair false { a: true }) { a: false }) From 05e12cb89f52690eaa1803a85b5768865e3207db Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 13:20:45 -0500 Subject: [PATCH 03/10] Update the changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e87c7859..481176f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v6.0.0](https://github.com/purescript/purescript-prelude/releases/tag/v6.0.0) - 2022-04-18 + Breaking changes: - Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez) - Change Generic Rep's `NoConstructors` to newtype `Void` (#282 by @JordanMartinez) From 2ea374c1e2feb57ccce709528d02171734652f7a Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Mon, 18 Apr 2022 14:04:57 -0500 Subject: [PATCH 04/10] Update .github/workflows/ci.yml Co-authored-by: Thomas Honeyman --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6721e67a..5ecfc781 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: purescript: "unstable" - purs-tidy: "stable" + purs-tidy: "latest" - uses: actions/setup-node@v1 with: From 8f4395aa34079598f0c99499b48e6031d0fd6c78 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 14:06:46 -0500 Subject: [PATCH 05/10] Drop blank line --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5ecfc781..d6f6cf6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,5 @@ jobs: bower install npm run-script test --if-present - - name: Check formatting run: purs-tidy check src test \ No newline at end of file From 083c6dd0b3e77f6a6106d8f1f0d223ce256f35c4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 14:17:00 -0500 Subject: [PATCH 06/10] Fix purs-tidy indentation in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6f6cf6b..cb151625 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: purescript: "unstable" - purs-tidy: "latest" + purs-tidy: "latest" - uses: actions/setup-node@v1 with: From 7e7250faf15b74e14a51d5c7973540f8358470f5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 18 Apr 2022 14:25:33 -0500 Subject: [PATCH 07/10] Add blank line to end of file --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb151625..ee417e55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,4 +35,4 @@ jobs: npm run-script test --if-present - name: Check formatting - run: purs-tidy check src test \ No newline at end of file + run: purs-tidy check src test From d925b71a85fab36206b031f72a3d02d8712038cd Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 19 Apr 2022 16:23:53 -0500 Subject: [PATCH 08/10] Drop purs-tidy check in CI --- .github/workflows/ci.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee417e55..aa57eb55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,6 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: purescript: "unstable" - purs-tidy: "latest" - uses: actions/setup-node@v1 with: @@ -33,6 +32,3 @@ jobs: run: | bower install npm run-script test --if-present - - - name: Check formatting - run: purs-tidy check src test From b2b63aadf2a1808eb19b41ee21518fcfc5e93046 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 19 Apr 2022 16:51:42 -0500 Subject: [PATCH 09/10] Update node to 14 in CI --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa57eb55..07fb36b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,9 +15,9 @@ jobs: with: purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "12" + node-version: "14.x" - name: Install dependencies run: | From 1348370c1b6dcec0fdc56d6a56f716869e4e008a Mon Sep 17 00:00:00 2001 From: JordanMartinez Date: Wed, 27 Apr 2022 08:36:14 -0500 Subject: [PATCH 10/10] Update CHANGELOG.md Co-authored-by: Thomas Honeyman --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 481176f1..c98cd441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Bugfixes: Other improvements: -## [v6.0.0](https://github.com/purescript/purescript-prelude/releases/tag/v6.0.0) - 2022-04-18 +## [v6.0.0](https://github.com/purescript/purescript-prelude/releases/tag/v6.0.0) - 2022-04-27 Breaking changes: - Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez)