Skip to content

Commit da43e7d

Browse files
authored
Merge pull request #175 from purescript/compiler/0.12
Update for PureScript 0.12
2 parents e903fd2 + c276ea0 commit da43e7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1067
-60
lines changed

LICENSE

+22-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
The MIT License (MIT)
1+
Copyright 2018 PureScript
22

3-
Copyright (c) 2015 PureScript
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so,
10-
subject to the following conditions:
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
1412

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "purescript-prelude",
33
"homepage": "https://github.com/purescript/purescript-prelude",
44
"description": "The PureScript Prelude",
5-
"license": "MIT",
5+
"license": "BSD-3-Clause",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/purescript/purescript-prelude.git"

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
55
"build": "eslint src && pulp build -- --censor-lib --strict",
6-
"test": "pulp test"
6+
"test": "pulp test --no-check-main"
77
},
88
"devDependencies": {
9-
"eslint": "^3.17.1",
10-
"purescript-psa": "^0.5.0-rc.1",
11-
"pulp": "^10.0.4",
12-
"rimraf": "^2.6.1"
9+
"eslint": "^4.19.1",
10+
"purescript-psa": "^0.6.0",
11+
"pulp": "^12.2.0",
12+
"rimraf": "^2.6.2"
1313
}
1414
}

src/Control/Applicative.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Data.Unit (Unit, unit)
2525
-- | Instances must satisfy the following laws in addition to the `Apply`
2626
-- | laws:
2727
-- |
28-
-- | - Identity: `(pure id) <*> v = v`
28+
-- | - Identity: `(pure identity) <*> v = v`
2929
-- | - Composition: `pure (<<<) <*> f <*> g <*> h = f <*> (g <*> h)`
3030
-- | - Homomorphism: `(pure f) <*> (pure x) = pure (f x)`
3131
-- | - Interchange: `u <*> (pure y) = (pure (_ $ y)) <*> u`

src/Control/Apply.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Control.Apply
88

99
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
1010
import Data.Function (const)
11-
import Control.Category (id)
11+
import Control.Category (identity)
1212

1313
-- | The `Apply` class provides the `(<*>)` which is used to apply a function
1414
-- | to an argument under a type constructor.
@@ -53,7 +53,7 @@ infixl 4 applyFirst as <*
5353

5454
-- | Combine two effectful actions, keeping only the result of the second.
5555
applySecond :: forall a b f. Apply f => f a -> f b -> f b
56-
applySecond a b = const id <$> a <*> b
56+
applySecond a b = const identity <$> a <*> b
5757

5858
infixl 4 applySecond as *>
5959

src/Control/Bind.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Control.Bind
1313

1414
import Control.Applicative (class Applicative, liftA1, pure, unless, when)
1515
import Control.Apply (class Apply, apply, (*>), (<*), (<*>))
16-
import Control.Category (id)
16+
import Control.Category (identity)
1717

1818
import Data.Function (flip)
1919
import Data.Functor (class Functor, map, void, ($>), (<#>), (<$), (<$>))
@@ -81,7 +81,7 @@ instance discardUnit :: Discard Unit where
8181

8282
-- | Collapse two applications of a monadic type constructor into one.
8383
join :: forall a m. Bind m => m (m a) -> m a
84-
join m = m >>= id
84+
join m = m >>= identity
8585

8686
-- | Forwards Kleisli composition.
8787
-- |

src/Control/Category.purs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Control.Category
2-
( class Category, id
2+
( class Category, identity
33
, module Control.Semigroupoid
44
) where
55

@@ -12,9 +12,9 @@ import Control.Semigroupoid (class Semigroupoid, compose, (<<<), (>>>))
1212
-- | Instances must satisfy the following law in addition to the
1313
-- | `Semigroupoid` law:
1414
-- |
15-
-- | - Identity: `id <<< p = p <<< id = p`
15+
-- | - Identity: `identity <<< p = p <<< identity = p`
1616
class Semigroupoid a <= Category a where
17-
id :: forall t. a t t
17+
identity :: forall t. a t t
1818

1919
instance categoryFn :: Category (->) where
20-
id x = x
20+
identity x = x

src/Control/Semigroupoid.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Control.Semigroupoid where
22

33
-- | A `Semigroupoid` is similar to a [`Category`](#category) but does not
4-
-- | require an identity element `id`, just composable morphisms.
4+
-- | require an identity element `identity`, just composable morphisms.
55
-- |
66
-- | `Semigroupoid`s must satisfy the following law:
77
-- |

src/Data/BooleanAlgebra.purs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
module Data.BooleanAlgebra
22
( class BooleanAlgebra
33
, module Data.HeytingAlgebra
4+
, class BooleanAlgebraRecord
45
) where
56

6-
import Data.HeytingAlgebra (class HeytingAlgebra, ff, tt, implies, conj, disj, not, (&&), (||))
7+
import Data.HeytingAlgebra (class HeytingAlgebra, class HeytingAlgebraRecord, ff, tt, implies, conj, disj, not, (&&), (||))
8+
import Data.Symbol (class IsSymbol)
79
import Data.Unit (Unit)
10+
import Prim.Row as Row
11+
import Prim.RowList as RL
812

913
-- | The `BooleanAlgebra` type class represents types that behave like boolean
1014
-- | values.
@@ -19,3 +23,18 @@ class HeytingAlgebra a <= BooleanAlgebra a
1923
instance booleanAlgebraBoolean :: BooleanAlgebra Boolean
2024
instance booleanAlgebraUnit :: BooleanAlgebra Unit
2125
instance booleanAlgebraFn :: BooleanAlgebra b => BooleanAlgebra (a -> b)
26+
instance booleanAlgebraRecord :: (RL.RowToList row list, BooleanAlgebraRecord list row row) => BooleanAlgebra (Record row)
27+
28+
-- | A class for records where all fields have `BooleanAlgebra` instances, used
29+
-- | to implement the `BooleanAlgebra` instance for records.
30+
class HeytingAlgebraRecord rowlist row subrow <= BooleanAlgebraRecord rowlist row subrow | rowlist -> subrow
31+
32+
instance booleanAlgebraRecordNil :: BooleanAlgebraRecord RL.Nil row ()
33+
34+
instance booleanAlgebraRecordCons
35+
:: ( IsSymbol key
36+
, Row.Cons key focus subrowTail subrow
37+
, BooleanAlgebraRecord rowlistTail row subrowTail
38+
, BooleanAlgebra focus
39+
)
40+
=> BooleanAlgebraRecord (RL.Cons key focus rowlistTail) row subrow

src/Data/CommutativeRing.purs

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ module Data.CommutativeRing
22
( class CommutativeRing
33
, module Data.Ring
44
, module Data.Semiring
5+
, class CommutativeRingRecord
56
) where
67

7-
import Data.Ring (class Ring)
8+
import Data.Ring (class Ring, class RingRecord)
89
import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
10+
import Data.Symbol (class IsSymbol)
911
import Data.Unit (Unit)
12+
import Prim.Row as Row
13+
import Prim.RowList as RL
1014

1115
-- | The `CommutativeRing` class is for rings where multiplication is
1216
-- | commutative.
@@ -21,3 +25,18 @@ instance commutativeRingInt :: CommutativeRing Int
2125
instance commutativeRingNumber :: CommutativeRing Number
2226
instance commutativeRingUnit :: CommutativeRing Unit
2327
instance commutativeRingFn :: CommutativeRing b => CommutativeRing (a -> b)
28+
instance commutativeRingRecord :: (RL.RowToList row list, CommutativeRingRecord list row row) => CommutativeRing (Record row)
29+
30+
-- | A class for records where all fields have `CommutativeRing` instances, used
31+
-- | to implement the `CommutativeRing` instance for records.
32+
class RingRecord rowlist row subrow <= CommutativeRingRecord rowlist row subrow | rowlist -> subrow
33+
34+
instance commutativeRingRecordNil :: CommutativeRingRecord RL.Nil row ()
35+
36+
instance commutativeRingRecordCons
37+
:: ( IsSymbol key
38+
, Row.Cons key focus subrowTail subrow
39+
, CommutativeRingRecord rowlistTail row subrowTail
40+
, CommutativeRing focus
41+
)
42+
=> CommutativeRingRecord (RL.Cons key focus rowlistTail) row subrow

src/Data/DivisionRing.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module Data.DivisionRing
77
, module Data.Semiring
88
) where
99

10+
import Data.EuclideanRing ((/))
1011
import Data.Ring (class Ring, negate, sub)
1112
import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
12-
import Data.EuclideanRing ((/))
1313

1414
-- | The `DivisionRing` class is for non-zero rings in which every non-zero
1515
-- | element has a multiplicative inverse. Division rings are sometimes also

src/Data/Eq.purs

+31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module Data.Eq
22
( class Eq, eq, (==), notEq, (/=)
33
, class Eq1, eq1, notEq1
4+
, class EqRecord, eqRecord
45
) where
56

7+
import Data.HeytingAlgebra ((&&))
8+
import Data.Symbol (class IsSymbol, SProxy(..), reflectSymbol)
69
import Data.Unit (Unit)
710
import Data.Void (Void)
11+
import Prim.Row as Row
12+
import Prim.RowList as RL
13+
import Record.Unsafe (unsafeGet)
14+
import Type.Data.RowList (RLProxy(..))
815

916
-- | The `Eq` type class represents types which support decidable equality.
1017
-- |
@@ -54,6 +61,9 @@ instance eqVoid :: Eq Void where
5461
instance eqArray :: Eq a => Eq (Array a) where
5562
eq = eqArrayImpl eq
5663

64+
instance eqRec :: (RL.RowToList row list, EqRecord list row) => Eq (Record row) where
65+
eq = eqRecord (RLProxy :: RLProxy list)
66+
5767
foreign import refEq :: forall a. a -> a -> Boolean
5868
foreign import eqArrayImpl :: forall a. (a -> a -> Boolean) -> Array a -> Array a -> Boolean
5969

@@ -66,3 +76,24 @@ instance eq1Array :: Eq1 Array where
6676

6777
notEq1 :: forall f a. Eq1 f => Eq a => f a -> f a -> Boolean
6878
notEq1 x y = (x `eq1` y) == false
79+
80+
-- | A class for records where all fields have `Eq` instances, used to implement
81+
-- | the `Eq` instance for records.
82+
class EqRecord rowlist row where
83+
eqRecord :: RLProxy rowlist -> Record row -> Record row -> Boolean
84+
85+
instance eqRowNil :: EqRecord RL.Nil row where
86+
eqRecord _ _ _ = true
87+
88+
instance eqRowCons
89+
:: ( EqRecord rowlistTail row
90+
, Row.Cons key focus rowTail row
91+
, IsSymbol key
92+
, Eq focus
93+
)
94+
=> EqRecord (RL.Cons key focus rowlistTail) row where
95+
eqRecord _ ra rb = (get ra == get rb) && tail
96+
where
97+
key = reflectSymbol (SProxy :: SProxy key)
98+
get = unsafeGet key :: Record row -> focus
99+
tail = eqRecord (RLProxy :: RLProxy rowlistTail) ra rb

src/Data/EuclideanRing.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ exports.intDegree = function (x) {
44
return Math.min(Math.abs(x), 2147483647);
55
};
66

7+
// See the Euclidean definition in
8+
// https://en.m.wikipedia.org/wiki/Modulo_operation.
79
exports.intDiv = function (x) {
810
return function (y) {
9-
/* jshint bitwise: false */
10-
return x / y | 0;
11+
if (y === 0) return 0;
12+
return y > 0 ? Math.floor(x / y) : -Math.floor(x / -y);
1113
};
1214
};
1315

1416
exports.intMod = function (x) {
1517
return function (y) {
16-
return x % y;
18+
if (y === 0) return 0;
19+
var yy = Math.abs(y);
20+
return ((x % yy) + yy) % yy;
1721
};
1822
};
1923

src/Data/EuclideanRing.purs

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
4141
-- | for `degree` is simply `const 1`. In fact, unless there's a specific
4242
-- | reason not to, `Field` types should normally use this definition of
4343
-- | `degree`.
44+
-- |
45+
-- | The `EuclideanRing Int` instance is one of the most commonly used
46+
-- | `EuclideanRing` instances and deserves a little more discussion. In
47+
-- | particular, there are a few different sensible law-abiding implementations
48+
-- | to choose from, with slightly different behaviour in the presence of
49+
-- | negative dividends or divisors. The most common definitions are "truncating"
50+
-- | division, where the result of `a / b` is rounded towards 0, and "Knuthian"
51+
-- | or "flooring" division, where the result of `a / b` is rounded towards
52+
-- | negative infinity. A slightly less common, but arguably more useful, option
53+
-- | is "Euclidean" division, which is defined so as to ensure that ``a `mod` b``
54+
-- | is always nonnegative. With Euclidean division, `a / b` rounds towards
55+
-- | negative infinity if the divisor is positive, and towards positive infinity
56+
-- | if the divisor is negative. Note that all three definitions are identical if
57+
-- | we restrict our attention to nonnegative dividends and divisors.
58+
-- |
59+
-- | In versions 1.x, 2.x, and 3.x of the Prelude, the `EuclideanRing Int`
60+
-- | instance used truncating division. As of 4.x, the `EuclideanRing Int`
61+
-- | instance uses Euclidean division. Additional functions `quot` and `rem` are
62+
-- | supplied if truncating division is desired.
4463
class CommutativeRing a <= EuclideanRing a where
4564
degree :: a -> Int
4665
div :: a -> a -> a

src/Data/Field.purs

+21-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,27 @@ import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
1515

1616
-- | The `Field` class is for types that are (commutative) fields.
1717
-- |
18-
-- | Instances must satisfy the following law in addition to the
19-
-- | `EuclideanRing` laws:
18+
-- | Mathematically, a field is a ring which is commutative and in which every
19+
-- | nonzero element has a multiplicative inverse; these conditions correspond
20+
-- | to the `CommutativeRing` and `DivisionRing` classes in PureScript
21+
-- | respectively. However, the `Field` class has `EuclideanRing` and
22+
-- | `DivisionRing` as superclasses, which seems like a stronger requirement
23+
-- | (since `CommutativeRing` is a superclass of `EuclideanRing`). In fact, it
24+
-- | is not stronger, since any type which has law-abiding `CommutativeRing`
25+
-- | and `DivisionRing` instances permits exactly one law-abiding
26+
-- | `EuclideanRing` instance. We use a `EuclideanRing` superclass here in
27+
-- | order to ensure that a `Field` constraint on a function permits you to use
28+
-- | `div` on that type, since `div` is a member of `EuclideanRing`.
2029
-- |
21-
-- | - Non-zero multiplicative inverse: ``a `mod` b = zero`` for all `a` and `b`
30+
-- | This class has no laws or members of its own; it exists as a convenience,
31+
-- | so a single constraint can be used when field-like behaviour is expected.
2232
-- |
23-
-- | If a type has a `Field` instance, it should also have a `DivisionRing`
24-
-- | instance. In a future release, `DivisionRing` may become a superclass of
25-
-- | `Field`.
26-
class EuclideanRing a <= Field a
33+
-- | This module also defines a single `Field` instance for any type which has
34+
-- | both `EuclideanRing` and `DivisionRing` instances. Any other instance
35+
-- | would overlap with this instance, so no other `Field` instances should be
36+
-- | defined in libraries. Instead, simply define `EuclideanRing` and
37+
-- | `DivisionRing` instances, and this will permit your type to be used with a
38+
-- | `Field` constraint.
39+
class (EuclideanRing a, DivisionRing a) <= Field a
2740

28-
instance fieldNumber :: Field Number
41+
instance field :: (EuclideanRing a, DivisionRing a) => Field a

src/Data/Function.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module Data.Function
88
, module Control.Category
99
) where
1010

11-
import Control.Category (id, compose, (<<<), (>>>))
11+
import Control.Category (identity, compose, (<<<), (>>>))
1212
import Data.Boolean (otherwise)
1313
import Data.Ord ((<=))
1414
import Data.Ring ((-))

src/Data/Functor.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Data.Unit (Unit, unit)
1919
-- |
2020
-- | Instances must satisfy the following laws:
2121
-- |
22-
-- | - Identity: `map id = id`
22+
-- | - Identity: `map identity = identity`
2323
-- | - Composition: `map (f <<< g) = map f <<< map g`
2424
class Functor f where
2525
map :: forall a b. (a -> b) -> f a -> f b

0 commit comments

Comments
 (0)