Skip to content

Commit 0f2085f

Browse files
committed
feat: upgrade to spago@next
1 parent 79c8320 commit 0f2085f

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

.github/workflows/ci.yml

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ jobs:
2727
.spago
2828
output
2929
30+
- name: Set up Node toolchain
31+
uses: actions/setup-node@v4
32+
33+
- name: Cache NPM dependencies
34+
uses: actions/cache@v4
35+
env:
36+
cache-name: cache-node-modules
37+
with:
38+
path: ~/.npm
39+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
40+
restore-keys: |
41+
${{ runner.os }}-build-${{ env.cache-name }}-
42+
${{ runner.os }}-build-
43+
${{ runner.os }}-
44+
45+
- name: Install NPM dependencies
46+
run: npm install
47+
3048
- name: Build source
3149
run: spago build --censor-stats --strict --pedantic-packages
3250

src/Data/BigInt.purs

+8-7
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ foreign import biCompare :: BigInt -> BigInt -> Int
159159

160160
instance ordBigInt :: Ord BigInt where
161161
compare x y = case biCompare x y of
162-
1 -> GT
163-
0 -> EQ
164-
_ -> LT
162+
1 -> GT
163+
0 -> EQ
164+
_ -> LT
165165

166166
-- | A decimal representation of the `BigInt` as a `String`.
167167
toString :: BigInt -> String
@@ -188,10 +188,10 @@ foreign import biAdd :: BigInt -> BigInt -> BigInt
188188
foreign import biMul :: BigInt -> BigInt -> BigInt
189189

190190
instance semiringBigInt :: Semiring BigInt where
191-
add = biAdd
191+
add = biAdd
192192
zero = fromInt 0
193-
mul = biMul
194-
one = fromInt 1
193+
mul = biMul
194+
one = fromInt 1
195195

196196
foreign import biSub :: BigInt -> BigInt -> BigInt
197197

@@ -207,7 +207,8 @@ instance euclideanRingBigInt :: EuclideanRing BigInt where
207207
div x y = (x - x `mod` y) `biDiv` y
208208

209209
mod x y = ((x `biMod` yy) + yy) `biMod` yy
210-
where yy = abs y
210+
where
211+
yy = abs y
211212

212213
degree = floor <<< toNumber <<< abs
213214

test/Test/Main.purs

+29-20
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ runSmallInt (SmallInt n) = n
3333

3434
-- | Arbitrary instance for BigInt
3535
newtype TestBigInt = TestBigInt BigInt
36+
3637
derive newtype instance eqTestBigInt :: Eq TestBigInt
3738
derive newtype instance ordTestBigInt :: Ord TestBigInt
3839
derive newtype instance semiringTestBigInt :: Semiring TestBigInt
@@ -43,21 +44,24 @@ derive newtype instance euclideanRingTestBigInt :: EuclideanRing TestBigInt
4344
instance arbitraryBigInt :: Arbitrary TestBigInt where
4445
arbitrary = do
4546
n <- (fromMaybe zero <<< fromString) <$> digitString
46-
op <- elements (cons' identity [negate])
47+
op <- elements (cons' identity [ negate ])
4748
pure (TestBigInt (op n))
48-
where digits :: Gen Int
49-
digits = chooseInt 0 9
50-
digitString :: Gen String
51-
digitString = (fold <<< map show) <$> (resize 50 $ arrayOf digits)
49+
where
50+
digits :: Gen Int
51+
digits = chooseInt 0 9
52+
53+
digitString :: Gen String
54+
digitString = (fold <<< map show) <$> (resize 50 $ arrayOf digits)
5255

5356
-- | Convert SmallInt to BigInt
5457
fromSmallInt :: SmallInt -> BigInt
5558
fromSmallInt = fromInt <<< runSmallInt
5659

5760
-- | Test if a binary relation holds before and after converting to BigInt.
58-
testBinary :: (BigInt -> BigInt -> BigInt)
59-
-> (Int -> Int -> Int)
60-
-> Effect Unit
61+
testBinary
62+
:: (BigInt -> BigInt -> BigInt)
63+
-> (Int -> Int -> Int)
64+
-> Effect Unit
6165
testBinary f g = quickCheck (\x y -> (fromInt x) `f` (fromInt y) == fromInt (x `g` y))
6266

6367
main :: Effect Unit
@@ -89,16 +93,18 @@ main = do
8993
assert $ toString (fromInt 12345) == "12345"
9094

9195
log "Converting bigints to arrays with a different base"
92-
assert $ NEA.toArray (digitsInBase 2 four).value == [1, 0, 0]
93-
assert $ (NEA.toArray <<< _.value <<< digitsInBase 16 <$>
94-
fromString "255") == Just [15, 15]
96+
assert $ NEA.toArray (digitsInBase 2 four).value == [ 1, 0, 0 ]
97+
assert $
98+
( NEA.toArray <<< _.value <<< digitsInBase 16 <$>
99+
fromString "255"
100+
) == Just [ 15, 15 ]
95101
assert $ NEA.toArray (digitsInBase 10 $ fromInt 12345).value
96-
== [1, 2, 3, 4, 5]
102+
== [ 1, 2, 3, 4, 5 ]
97103

98104
assert $ toBase' 2 four == unsafePartial unsafeFromString "100"
99105
assert $ (toBase' 16 <$> fromString "255") == NES.fromString "ff"
100106
assert $ toNonEmptyString (fromInt 12345)
101-
== unsafePartial unsafeFromString "12345"
107+
== unsafePartial unsafeFromString "12345"
102108

103109
log "Converting from Number to BigInt"
104110
assert $ fromNumber 0.0 == Just zero
@@ -140,7 +146,7 @@ main = do
140146
assert $ zero `pow` zero == one
141147

142148
log "Prime numbers"
143-
assert $ filter (prime <<< fromInt) (range 2 20) == [2, 3, 5, 7, 11, 13, 17, 19]
149+
assert $ filter (prime <<< fromInt) (range 2 20) == [ 2, 3, 5, 7, 11, 13, 17, 19 ]
144150

145151
log "Absolute value"
146152
quickCheck $ \(TestBigInt x) -> abs x == if x > zero then x else (-x)
@@ -178,12 +184,15 @@ main = do
178184
assert $ (fromString "-2147483649" >>= toInt) == Nothing
179185
assert $ (fromString "921231231322337203685124775809" >>= toInt) == Nothing
180186
assert $ (fromString "-922337203612312312312854775809" >>= toInt) == Nothing
181-
quickCheck (\a b c ->
182-
let x = add (fromInt a) (add (fromInt b) (fromInt c))
183-
in case toInt x of
184-
Nothing -> x < fromInt (-2147483648) || x > fromInt 2147483647
185-
Just i -> fromInt i == x
186-
)
187+
quickCheck
188+
( \a b c ->
189+
let
190+
x = add (fromInt a) (add (fromInt b) (fromInt c))
191+
in
192+
case toInt x of
193+
Nothing -> x < fromInt (-2147483648) || x > fromInt 2147483647
194+
Just i -> fromInt i == x
195+
)
187196

188197
log "Type Level Int creation"
189198
assert $ toString (fromTLInt (Proxy :: Proxy 921231231322337203685124775809)) == "921231231322337203685124775809"

0 commit comments

Comments
 (0)