Skip to content

Commit 3850da9

Browse files
authored
Merge pull request #33 from purescript/compiler/0.12
Update for PureScript 0.12
2 parents f9b5e3e + 99b1523 commit 3850da9

File tree

8 files changed

+117
-47
lines changed

8 files changed

+117
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/bower_components/
66
/node_modules/
77
/output/
8+
package-lock.json

LICENSE

Lines changed: 22 additions & 16 deletions
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) 2014 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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "purescript-integers",
33
"homepage": "https://github.com/purescript/purescript-integers",
4-
"description": "Functions and bitwise operators for the Int numeric type",
5-
"license": "MIT",
4+
"license": "BSD-3-Clause",
65
"repository": {
76
"type": "git",
87
"url": "git://github.com/purescript/purescript-integers.git"
@@ -17,13 +16,14 @@
1716
"package.json"
1817
],
1918
"dependencies": {
20-
"purescript-globals": "^3.0.0",
21-
"purescript-math": "^2.0.0",
22-
"purescript-maybe": "^3.0.0",
23-
"purescript-partial": "^1.2.0"
19+
"purescript-globals": "^4.0.0",
20+
"purescript-math": "^2.1.1",
21+
"purescript-maybe": "^4.0.0",
22+
"purescript-prelude": "^4.0.0"
2423
},
2524
"devDependencies": {
26-
"purescript-assert": "^3.0.0",
27-
"purescript-console": "^3.0.0"
25+
"purescript-assert": "^4.0.0",
26+
"purescript-console": "^4.0.0",
27+
"purescript-partial": "^2.0.0"
2828
}
2929
}

package.json

Lines changed: 5 additions & 5 deletions
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 --check-main-type Effect.Effect"
77
},
88
"devDependencies": {
9-
"eslint": "^3.17.1",
10-
"pulp": "^10.0.4",
11-
"purescript-psa": "^0.5.0-rc.1",
12-
"rimraf": "^2.6.1"
9+
"eslint": "^4.19.1",
10+
"pulp": "^12.2.0",
11+
"purescript-psa": "^0.6.0",
12+
"rimraf": "^2.6.2"
1313
}
1414
}

src/Data/Int.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use strict";
22

3-
// module Data.Int
4-
53
exports.fromNumberImpl = function (just) {
64
return function (nothing) {
75
return function (n) {
@@ -47,6 +45,20 @@ exports.toStringAs = function (radix) {
4745
};
4846
};
4947

48+
49+
exports.quot = function (x) {
50+
return function (y) {
51+
/* jshint bitwise: false */
52+
return x / y | 0;
53+
};
54+
};
55+
56+
exports.rem = function (x) {
57+
return function (y) {
58+
return x % y;
59+
};
60+
};
61+
5062
exports.pow = function (x) {
5163
return function (y) {
5264
/* jshint bitwise: false */

src/Data/Int.purs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Data.Int
1818
, parity
1919
, even
2020
, odd
21+
, quot
22+
, rem
2123
, pow
2224
) where
2325

@@ -134,9 +136,7 @@ instance euclideanRingParity :: EuclideanRing Parity where
134136
mod _ _ = Even
135137

136138
instance divisionRingParity :: DivisionRing Parity where
137-
recip = id
138-
139-
instance fieldParity :: Field Parity
139+
recip = identity
140140

141141
-- | Returns whether an `Int` is `Even` or `Odd`.
142142
-- |
@@ -204,6 +204,41 @@ radix n | n >= 2 && n <= 36 = Just (Radix n)
204204
fromStringAs :: Radix -> String -> Maybe Int
205205
fromStringAs = fromStringAsImpl Just Nothing
206206

207+
-- | The `quot` function provides _truncating_ integer division (see the
208+
-- | documentation for the `EuclideanRing` class). It is identical to `div` in
209+
-- | the `EuclideanRing Int` instance if the dividend is positive, but will be
210+
-- | slightly different if the dividend is negative. For example:
211+
-- |
212+
-- | ```purescript
213+
-- | div 2 3 == 0
214+
-- | quot 2 3 == 0
215+
-- |
216+
-- | div (-2) 3 == (-1)
217+
-- | quot (-2) 3 == 0
218+
-- |
219+
-- | div 2 (-3) == 0
220+
-- | quot 2 (-3) == 0
221+
-- | ```
222+
foreign import quot :: Int -> Int -> Int
223+
224+
-- | The `rem` function provides the remainder after _truncating_ integer
225+
-- | division (see the documentation for the `EuclideanRing` class). It is
226+
-- | identical to `mod` in the `EuclideanRing Int` instance if the dividend is
227+
-- | positive, but will be slightly different if the dividend is negative. For
228+
-- | example:
229+
-- |
230+
-- | ```purescript
231+
-- | mod 2 3 == 2
232+
-- | rem 2 3 == 2
233+
-- |
234+
-- | mod (-2) 3 == 1
235+
-- | rem (-2) 3 == (-2)
236+
-- |
237+
-- | mod 2 (-3) == 2
238+
-- | rem 2 (-3) == 2
239+
-- | ```
240+
foreign import rem :: Int -> Int -> Int
241+
207242
-- | Raise an Int to the power of another Int.
208243
foreign import pow :: Int -> Int -> Int
209244

test/Test/Data/Int.purs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@ module Test.Data.Int (testInt) where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE, log)
7-
8-
import Data.Int (parity, odd, even, fromString, floor, ceil, round, toNumber, fromNumber, fromStringAs, binary, octal, hexadecimal, radix, toStringAs, pow)
5+
import Data.Int (binary, ceil, even, floor, fromNumber, fromString, fromStringAs, hexadecimal, octal, odd, parity, pow, quot, radix, rem, round, toNumber, toStringAs)
96
import Data.Maybe (Maybe(..), fromJust)
10-
7+
import Effect (Effect)
8+
import Effect.Console (log)
119
import Global (nan, infinity)
12-
1310
import Partial.Unsafe (unsafePartial)
11+
import Test.Assert (assert)
1412

15-
import Test.Assert (ASSERT, assert)
16-
17-
testInt :: Eff (console :: CONSOLE, assert :: ASSERT) Unit
13+
testInt :: Effect Unit
1814
testInt = do
1915

2016
log "fromNumber should coerce integer values"
@@ -151,6 +147,28 @@ testInt = do
151147
go 3 8
152148
go 49 171
153149

150+
log "quotient/remainder law"
151+
do
152+
let
153+
go a b =
154+
let
155+
q = quot a b
156+
r = rem a b
157+
msg = show a <> " / " <> show b <> ": "
158+
in do
159+
assert $ q * b + r == a
160+
-- Check when dividend goes into divisor exactly
161+
go 8 2
162+
go (-8) 2
163+
go 8 (-2)
164+
go (-8) (-2)
165+
166+
-- Check when dividend does not go into divisor exactly
167+
go 2 3
168+
go (-2) 3
169+
go 2 (-3)
170+
go (-2) (-3)
171+
154172
log "pow"
155173
assert $ pow 2 2 == 4
156174
assert $ pow 5 3 == 125

test/Test/Main.purs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Eff (Eff)
6-
import Control.Monad.Eff.Console (CONSOLE)
5+
import Effect (Effect)
76

8-
import Test.Assert (ASSERT)
97
import Test.Data.Int (testInt)
108

11-
main :: Eff (console :: CONSOLE, assert :: ASSERT) Unit
9+
main :: Effect Unit
1210
main = testInt

0 commit comments

Comments
 (0)