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: | diff --git a/CHANGELOG.md b/CHANGELOG.md index e87c7859..c98cd441 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-27 + Breaking changes: - Migrated FFI to ES Modules (#287 by @kl0tl and @JordanMartinez) - Change Generic Rep's `NoConstructors` to newtype `Void` (#282 by @JordanMartinez) 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 })