Skip to content

Commit

Permalink
Merge pull request #33 from purescript/compiler/0.12
Browse files Browse the repository at this point in the history
Update for PureScript 0.12
  • Loading branch information
garyb committed May 23, 2018
2 parents f9b5e3e + 99b1523 commit 3850da9
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@
/bower_components/
/node_modules/
/output/
package-lock.json
38 changes: 22 additions & 16 deletions LICENSE
@@ -1,20 +1,26 @@
The MIT License (MIT)
Copyright 2018 PureScript

Copyright (c) 2014 PureScript
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 changes: 8 additions & 8 deletions bower.json
@@ -1,8 +1,7 @@
{
"name": "purescript-integers",
"homepage": "https://github.com/purescript/purescript-integers",
"description": "Functions and bitwise operators for the Int numeric type",
"license": "MIT",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git://github.com/purescript/purescript-integers.git"
Expand All @@ -17,13 +16,14 @@
"package.json"
],
"dependencies": {
"purescript-globals": "^3.0.0",
"purescript-math": "^2.0.0",
"purescript-maybe": "^3.0.0",
"purescript-partial": "^1.2.0"
"purescript-globals": "^4.0.0",
"purescript-math": "^2.1.1",
"purescript-maybe": "^4.0.0",
"purescript-prelude": "^4.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0"
"purescript-assert": "^4.0.0",
"purescript-console": "^4.0.0",
"purescript-partial": "^2.0.0"
}
}
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -3,12 +3,12 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test"
"test": "pulp test --check-main-type Effect.Effect"
},
"devDependencies": {
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
"eslint": "^4.19.1",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
16 changes: 14 additions & 2 deletions src/Data/Int.js
@@ -1,7 +1,5 @@
"use strict";

// module Data.Int

exports.fromNumberImpl = function (just) {
return function (nothing) {
return function (n) {
Expand Down Expand Up @@ -47,6 +45,20 @@ exports.toStringAs = function (radix) {
};
};


exports.quot = function (x) {
return function (y) {
/* jshint bitwise: false */
return x / y | 0;
};
};

exports.rem = function (x) {
return function (y) {
return x % y;
};
};

exports.pow = function (x) {
return function (y) {
/* jshint bitwise: false */
Expand Down
41 changes: 38 additions & 3 deletions src/Data/Int.purs
Expand Up @@ -18,6 +18,8 @@ module Data.Int
, parity
, even
, odd
, quot
, rem
, pow
) where

Expand Down Expand Up @@ -134,9 +136,7 @@ instance euclideanRingParity :: EuclideanRing Parity where
mod _ _ = Even

instance divisionRingParity :: DivisionRing Parity where
recip = id

instance fieldParity :: Field Parity
recip = identity

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

-- | The `quot` function provides _truncating_ integer division (see the
-- | documentation for the `EuclideanRing` class). It is identical to `div` in
-- | the `EuclideanRing Int` instance if the dividend is positive, but will be
-- | slightly different if the dividend is negative. For example:
-- |
-- | ```purescript
-- | div 2 3 == 0
-- | quot 2 3 == 0
-- |
-- | div (-2) 3 == (-1)
-- | quot (-2) 3 == 0
-- |
-- | div 2 (-3) == 0
-- | quot 2 (-3) == 0
-- | ```
foreign import quot :: Int -> Int -> Int

-- | The `rem` function provides the remainder after _truncating_ integer
-- | division (see the documentation for the `EuclideanRing` class). It is
-- | identical to `mod` in the `EuclideanRing Int` instance if the dividend is
-- | positive, but will be slightly different if the dividend is negative. For
-- | example:
-- |
-- | ```purescript
-- | mod 2 3 == 2
-- | rem 2 3 == 2
-- |
-- | mod (-2) 3 == 1
-- | rem (-2) 3 == (-2)
-- |
-- | mod 2 (-3) == 2
-- | rem 2 (-3) == 2
-- | ```
foreign import rem :: Int -> Int -> Int

-- | Raise an Int to the power of another Int.
foreign import pow :: Int -> Int -> Int

Expand Down
36 changes: 27 additions & 9 deletions test/Test/Data/Int.purs
Expand Up @@ -2,19 +2,15 @@ module Test.Data.Int (testInt) where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)

import Data.Int (parity, odd, even, fromString, floor, ceil, round, toNumber, fromNumber, fromStringAs, binary, octal, hexadecimal, radix, toStringAs, pow)
import Data.Int (binary, ceil, even, floor, fromNumber, fromString, fromStringAs, hexadecimal, octal, odd, parity, pow, quot, radix, rem, round, toNumber, toStringAs)
import Data.Maybe (Maybe(..), fromJust)

import Effect (Effect)
import Effect.Console (log)
import Global (nan, infinity)

import Partial.Unsafe (unsafePartial)
import Test.Assert (assert)

import Test.Assert (ASSERT, assert)

testInt :: Eff (console :: CONSOLE, assert :: ASSERT) Unit
testInt :: Effect Unit
testInt = do

log "fromNumber should coerce integer values"
Expand Down Expand Up @@ -151,6 +147,28 @@ testInt = do
go 3 8
go 49 171

log "quotient/remainder law"
do
let
go a b =
let
q = quot a b
r = rem a b
msg = show a <> " / " <> show b <> ": "
in do
assert $ q * b + r == a
-- Check when dividend goes into divisor exactly
go 8 2
go (-8) 2
go 8 (-2)
go (-8) (-2)

-- Check when dividend does not go into divisor exactly
go 2 3
go (-2) 3
go 2 (-3)
go (-2) (-3)

log "pow"
assert $ pow 2 2 == 4
assert $ pow 5 3 == 125
Expand Down
6 changes: 2 additions & 4 deletions test/Test/Main.purs
Expand Up @@ -2,11 +2,9 @@ module Test.Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Effect (Effect)

import Test.Assert (ASSERT)
import Test.Data.Int (testInt)

main :: Eff (console :: CONSOLE, assert :: ASSERT) Unit
main :: Effect Unit
main = testInt

0 comments on commit 3850da9

Please sign in to comment.