Skip to content

Commit 202a73c

Browse files
authored
Merge pull request #106 from phadej/ghc-9.6
base-4.18 and some-1.0.5
2 parents 0120d4b + 09fc08a commit 202a73c

File tree

26 files changed

+314
-833
lines changed

26 files changed

+314
-833
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
#
99
# For more information, see https://github.com/haskell-CI/haskell-ci
1010
#
11-
# version: 0.15.20220822
11+
# version: 0.15.20230313
1212
#
13-
# REGENDATA ("0.15.20220822",["github","--config=cabal.haskell-ci","cabal.project"])
13+
# REGENDATA ("0.15.20230313",["github","--config=cabal.haskell-ci","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -32,14 +32,19 @@ jobs:
3232
strategy:
3333
matrix:
3434
include:
35-
- compiler: ghc-9.4.1
35+
- compiler: ghc-9.6.1
3636
compilerKind: ghc
37-
compilerVersion: 9.4.1
37+
compilerVersion: 9.6.1
3838
setup-method: ghcup
3939
allow-failure: false
40-
- compiler: ghc-9.2.4
40+
- compiler: ghc-9.4.4
4141
compilerKind: ghc
42-
compilerVersion: 9.2.4
42+
compilerVersion: 9.4.4
43+
setup-method: ghcup
44+
allow-failure: false
45+
- compiler: ghc-9.2.7
46+
compilerKind: ghc
47+
compilerVersion: 9.2.7
4348
setup-method: ghcup
4449
allow-failure: false
4550
- compiler: ghc-9.0.2
@@ -98,15 +103,15 @@ jobs:
98103
curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup"
99104
chmod a+x "$HOME/.ghcup/bin/ghcup"
100105
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
101-
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
106+
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
102107
else
103108
apt-add-repository -y 'ppa:hvr/ghc'
104109
apt-get update
105110
apt-get install -y "$HCNAME"
106111
mkdir -p "$HOME/.ghcup/bin"
107112
curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup"
108113
chmod a+x "$HOME/.ghcup/bin/ghcup"
109-
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
114+
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
110115
fi
111116
env:
112117
HCKIND: ${{ matrix.compilerKind }}
@@ -124,13 +129,13 @@ jobs:
124129
echo "HC=$HC" >> "$GITHUB_ENV"
125130
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
126131
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
127-
echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
132+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
128133
else
129134
HC=$HCDIR/bin/$HCKIND
130135
echo "HC=$HC" >> "$GITHUB_ENV"
131136
echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV"
132137
echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV"
133-
echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
138+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
134139
fi
135140
136141
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
@@ -180,9 +185,9 @@ jobs:
180185
run: |
181186
$CABAL v2-update -v
182187
- name: cache (tools)
183-
uses: actions/cache@v2
188+
uses: actions/cache/restore@v3
184189
with:
185-
key: ${{ runner.os }}-${{ matrix.compiler }}-tools-2369439b
190+
key: ${{ runner.os }}-${{ matrix.compiler }}-tools-e3e6fd3b
186191
path: ~/.haskell-ci-tools
187192
- name: install cabal-plan
188193
run: |
@@ -206,8 +211,14 @@ jobs:
206211
run: |
207212
if [ $((HCNUMVER >= 80600 && HCNUMVER < 90000)) -ne 0 ] ; then $CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.20' ; fi
208213
if [ $((HCNUMVER >= 80600 && HCNUMVER < 90000)) -ne 0 ] ; then doctest --version ; fi
214+
- name: save cache (tools)
215+
uses: actions/cache/save@v3
216+
if: always()
217+
with:
218+
key: ${{ runner.os }}-${{ matrix.compiler }}-tools-e3e6fd3b
219+
path: ~/.haskell-ci-tools
209220
- name: checkout
210-
uses: actions/checkout@v2
221+
uses: actions/checkout@v3
211222
with:
212223
path: source
213224
- name: initial cabal.project for sdist
@@ -293,8 +304,8 @@ jobs:
293304
run: |
294305
$CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all
295306
cabal-plan
296-
- name: cache
297-
uses: actions/cache@v2
307+
- name: restore cache
308+
uses: actions/cache/restore@v3
298309
with:
299310
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
300311
path: ~/.cabal/store
@@ -334,8 +345,8 @@ jobs:
334345
if [ $((HCNUMVER >= 80600 && HCNUMVER < 90000)) -ne 0 ] ; then doctest -XHaskell2010 src ; fi
335346
- name: docspec
336347
run: |
337-
if [ $((HCNUMVER >= 80000)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all ; fi
338-
if [ $((HCNUMVER >= 80000)) -ne 0 ] ; then cabal-docspec $ARG_COMPILER ; fi
348+
if [ $((HCNUMVER >= 80600 && HCNUMVER < 90600)) -ne 0 ] ; then $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH all ; fi
349+
if [ $((HCNUMVER >= 80600 && HCNUMVER < 90600)) -ne 0 ] ; then cabal-docspec $ARG_COMPILER ; fi
339350
- name: cabal check
340351
run: |
341352
cd ${PKGDIR_bin} || false
@@ -358,7 +369,7 @@ jobs:
358369
${CABAL} -vnormal check
359370
- name: haddock
360371
run: |
361-
if [ $((HCNUMVER >= 80600)) -ne 0 ] ; then $CABAL v2-haddock $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all ; fi
372+
if [ $((HCNUMVER >= 80600)) -ne 0 ] ; then $CABAL v2-haddock --disable-documentation $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all ; fi
362373
- name: unconstrained build
363374
run: |
364375
rm -f cabal.project.local
@@ -394,3 +405,9 @@ jobs:
394405
run: |
395406
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='vec -distributive' --dependencies-only -j2 all
396407
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --constraint='vec -distributive' all
408+
- name: save cache
409+
uses: actions/cache/save@v3
410+
if: always()
411+
with:
412+
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
413+
path: ~/.cabal/store

.stylish-haskell.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ steps:
99
style: vertical
1010
remove_redundant: true
1111
- trailing_whitespace: {}
12-
columns: 80
12+
columns: 120
1313
language_extensions:
1414
- DataKinds
1515
- EmptyCase

bin/ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Version history for bin
22

3+
## 0.1.3
4+
5+
- Add `EqP` and `OrdP` instances.
6+
- Add `GShow Pos/P` instances.
7+
- Better 'PosP.toNatural' implementation.
8+
39
## 0.1.2
410

511
- Add `boring` instances

bin/bin.cabal

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cabal-version: 2.2
22
name: bin
3-
version: 0.1.2
4-
x-revision: 1
3+
version: 0.1.3
54
synopsis: Bin: binary natural numbers.
65
category: Data, Dependent Types, Singletons, Math
76
description:
@@ -44,8 +43,9 @@ tested-with:
4443
|| ==8.8.4
4544
|| ==8.10.7
4645
|| ==9.0.2
47-
|| ==9.2.4
48-
|| ==9.4.1
46+
|| ==9.2.7
47+
|| ==9.4.4
48+
|| ==9.6.1
4949

5050
source-repository head
5151
type: git
@@ -67,14 +67,14 @@ library
6767

6868
other-modules: TrustworthyCompat
6969
build-depends:
70-
, base >=4.7 && <4.18
70+
, base >=4.7 && <4.19
7171
, boring ^>=0.2
7272
, dec ^>=0.0.3
7373
, deepseq >=1.3.0.2 && <1.5
74-
, fin ^>=0.2
74+
, fin ^>=0.3
7575
, hashable >=1.2.7.0 && <1.5
7676
, QuickCheck ^>=2.14.2
77-
, some ^>=1.0.3
77+
, some ^>=1.0.4
7878

7979
if !impl(ghc >=7.10)
8080
build-depends: nats ^>=1.1.2

bin/src/Data/Bin/Pos.hs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE DeriveDataTypeable #-}
34
{-# LANGUAGE EmptyCase #-}
@@ -29,15 +30,21 @@ module Data.Bin.Pos (
2930
) where
3031

3132
import Prelude
32-
(Bounded (..), Eq, Int, Integer, Ord (..), Show (..), ShowS, String,
33-
fmap, fromIntegral, map, showParen, showString, ($), (.))
33+
(Bounded (..), Eq, Int, Integer, Ord (..), Show (..), ShowS, String, fmap, fromIntegral, map, showParen,
34+
showString, ($), (.))
3435

3536
import Control.DeepSeq (NFData (..))
3637
import Data.Bin (Bin (..), BinP (..))
3738
import Data.BinP.PosP (PosP (..))
39+
import Data.GADT.Show (GShow (..))
3840
import Data.Typeable (Typeable)
3941
import Numeric.Natural (Natural)
4042

43+
#if MIN_VERSION_some(1,0,5)
44+
import Data.EqP (EqP (..))
45+
import Data.OrdP (OrdP (..))
46+
#endif
47+
4148
import qualified Data.BinP.PosP as PP
4249
import qualified Data.Boring as Boring
4350
import qualified Data.Type.Bin as B
@@ -47,9 +54,12 @@ import qualified Test.QuickCheck as QC
4754
import Data.Type.Bin
4855

4956
-- $setup
50-
-- >>> import Prelude (map, putStrLn, Ord (..), Bounded (..), ($), (.))
57+
-- >>> import Prelude (map, putStrLn, Ord (..), Bounded (..), ($), (.), print)
5158
-- >>> import Data.Foldable (traverse_)
5259
-- >>> import Data.Type.Bin
60+
-- >>> import Data.EqP (eqp)
61+
-- >>> import Data.OrdP (comparep)
62+
-- >>> :set -XTypeApplications
5363

5464
-------------------------------------------------------------------------------
5565
-- Data
@@ -73,6 +83,40 @@ deriving instance Ord (Pos b)
7383
instance Show (Pos b) where
7484
showsPrec d = showsPrec d . toNatural
7585

86+
-- | @since 0.1.3
87+
instance GShow Pos where
88+
gshowsPrec = showsPrec
89+
90+
#if MIN_VERSION_some(1,0,5)
91+
-- |
92+
--
93+
-- >>> eqp (top :: Pos Bin4) (top :: Pos Bin6)
94+
-- True
95+
--
96+
-- >>> let xs = universe @Bin4; ys = universe @Bin6 in traverse_ print [ [ eqp x y | y <- ys ] | x <- xs ]
97+
-- [True,False,False,False,False,False]
98+
-- [False,True,False,False,False,False]
99+
-- [False,False,True,False,False,False]
100+
-- [False,False,False,True,False,False]
101+
--
102+
-- @since 0.1.3
103+
instance EqP Pos where
104+
eqp (Pos x) (Pos y) = eqp x y
105+
106+
-- |
107+
--
108+
-- >>> let xs = universe @Bin4; ys = universe @Bin6 in traverse_ print [ [ comparep x y | y <- ys ] | x <- xs ]
109+
-- [EQ,LT,LT,LT,LT,LT]
110+
-- [GT,EQ,LT,LT,LT,LT]
111+
-- [GT,GT,EQ,LT,LT,LT]
112+
-- [GT,GT,GT,EQ,LT,LT]
113+
--
114+
-- @since 0.1.3
115+
--
116+
instance OrdP Pos where
117+
comparep (Pos x) (Pos y) = comparep x y
118+
#endif
119+
76120
-- |
77121
--
78122
-- >>> minBound < (maxBound :: Pos Bin5)

bin/src/Data/BinP/PosP.hs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE BangPatterns #-}
13
{-# LANGUAGE DataKinds #-}
24
{-# LANGUAGE DeriveDataTypeable #-}
35
{-# LANGUAGE EmptyCase #-}
@@ -31,18 +33,23 @@ module Data.BinP.PosP (
3133
) where
3234

3335
import Prelude
34-
(Bounded (..), Either (..), Eq, Int, Integer, Num, Ord (..),
35-
Ordering (..), Show (..), ShowS, String, either, fmap, fromIntegral, map,
36-
showParen, showString, ($), (*), (+), (++), (.))
36+
(Bounded (..), Either (..), Eq (..), Int, Integer, Num, Ord (..), Ordering (..), Show (..), ShowS, String, either,
37+
fmap, fromIntegral, map, showParen, showString, ($), (*), (+), (++), (.))
3738

3839
import Control.DeepSeq (NFData (..))
3940
import Data.Bin (BinP (..))
41+
import Data.GADT.Show (GShow (..))
4042
import Data.Nat (Nat (..))
4143
import Data.Proxy (Proxy (..))
4244
import Data.Typeable (Typeable)
4345
import Data.Wrd (Wrd (..))
4446
import Numeric.Natural (Natural)
4547

48+
#if MIN_VERSION_some(1,0,5)
49+
import Data.EqP (EqP (..))
50+
import Data.OrdP (OrdP (..))
51+
#endif
52+
4653
import qualified Data.Bin as B
4754
import qualified Data.Boring as Boring
4855
import qualified Data.Type.Bin as B
@@ -84,6 +91,20 @@ instance Ord (PosP' n b) where
8491
compare (There1 x) (There1 y) = compare x y
8592
compare (There0 x) (There0 y) = compare x y
8693

94+
-------------------------------------------------------------------------------
95+
-- some
96+
-------------------------------------------------------------------------------
97+
98+
#if MIN_VERSION_some(1,0,5)
99+
-- | @since 0.1.3
100+
instance EqP PosP where
101+
eqp x y = toNatural x == toNatural y
102+
103+
-- | @since 0.1.3
104+
instance OrdP PosP where
105+
comparep x y = compare (toNatural x) (toNatural y)
106+
#endif
107+
87108
-------------------------------------------------------------------------------
88109
-- Instances
89110
-------------------------------------------------------------------------------
@@ -94,6 +115,14 @@ instance Show (PosP b) where
94115
instance N.SNatI n => Show (PosP' n b) where
95116
showsPrec d = showsPrec d . toNatural'
96117

118+
-- | @since 0.1.3
119+
instance GShow PosP where
120+
gshowsPrec = showsPrec
121+
122+
-- | @since 0.1.3
123+
instance N.SNatI n => GShow (PosP' n) where
124+
gshowsPrec = showsPrec
125+
97126
instance SBinPI b => Bounded (PosP b) where
98127
minBound = PosP minBound
99128
maxBound = PosP maxBound
@@ -201,14 +230,17 @@ explicitShowsPrec' d (There0 p)
201230

202231
-- | Convert 'PosP' to 'Natural'.
203232
toNatural :: PosP b -> Natural
204-
toNatural (PosP p) = toNatural' p
233+
toNatural (PosP p) = toNatural' p -- ' 0 1 p
205234

206235
-- | Convert 'PosP'' to 'Natural'.
207236
toNatural' :: forall n b. N.SNatI n => PosP' n b -> Natural
208-
toNatural' (AtEnd v) = W.toNatural v
209-
toNatural' (Here v) = W.toNatural v
210-
toNatural' (There1 p) = getKNat (exp2 :: KNat Natural n) + toNatural' p
211-
toNatural' (There0 p) = toNatural' p
237+
toNatural' = toNatural'' 0 (getKNat (exp2 :: KNat Natural n))
238+
239+
toNatural'' :: Natural -> Natural -> PosP' n b -> Natural
240+
toNatural'' !acc !_ (AtEnd v) = acc + W.toNatural v
241+
toNatural'' !acc !_ (Here v) = acc + W.toNatural v
242+
toNatural'' !acc !exp2n (There1 v) = toNatural'' (acc + exp2n) (2 * exp2n) v
243+
toNatural'' !acc !exp2n (There0 v) = toNatural'' acc (2 * exp2n) v
212244

213245
exp2 :: Num a => N.SNatI n => KNat a n
214246
exp2 = N.induction (KNat 1) (\(KNat n) -> KNat (n * 2))

0 commit comments

Comments
 (0)