Skip to content

Commit 9433a6f

Browse files
authored
Merge pull request #50 from haskellari/solo
Add Solo instance
2 parents c697ad1 + 3d1ddd9 commit 9433a6f

File tree

5 files changed

+117
-30
lines changed

5 files changed

+117
-30
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 88 additions & 25 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.12
11+
# version: 0.13.20211030
1212
#
13-
# REGENDATA ("0.12",["github","cabal.project"])
13+
# REGENDATA ("0.13.20211030",["github","cabal.project"])
1414
#
1515
name: Haskell-CI
1616
on:
@@ -30,61 +30,123 @@ jobs:
3030
strategy:
3131
matrix:
3232
include:
33+
- compiler: ghc-9.2.1
34+
compilerKind: ghc
35+
compilerVersion: 9.2.1
36+
setup-method: ghcup
37+
allow-failure: false
3338
- compiler: ghc-9.0.1
39+
compilerKind: ghc
40+
compilerVersion: 9.0.1
41+
setup-method: hvr-ppa
3442
allow-failure: false
3543
- compiler: ghc-8.10.4
44+
compilerKind: ghc
45+
compilerVersion: 8.10.4
46+
setup-method: hvr-ppa
3647
allow-failure: false
3748
- compiler: ghc-8.8.4
49+
compilerKind: ghc
50+
compilerVersion: 8.8.4
51+
setup-method: hvr-ppa
3852
allow-failure: false
3953
- compiler: ghc-8.6.5
54+
compilerKind: ghc
55+
compilerVersion: 8.6.5
56+
setup-method: hvr-ppa
4057
allow-failure: false
4158
- compiler: ghc-8.4.4
59+
compilerKind: ghc
60+
compilerVersion: 8.4.4
61+
setup-method: hvr-ppa
4262
allow-failure: false
4363
- compiler: ghc-8.2.2
64+
compilerKind: ghc
65+
compilerVersion: 8.2.2
66+
setup-method: hvr-ppa
4467
allow-failure: false
4568
- compiler: ghc-8.0.2
69+
compilerKind: ghc
70+
compilerVersion: 8.0.2
71+
setup-method: hvr-ppa
4672
allow-failure: false
4773
- compiler: ghc-7.10.3
74+
compilerKind: ghc
75+
compilerVersion: 7.10.3
76+
setup-method: hvr-ppa
4877
allow-failure: false
4978
- compiler: ghc-7.8.4
79+
compilerKind: ghc
80+
compilerVersion: 7.8.4
81+
setup-method: hvr-ppa
5082
allow-failure: false
5183
- compiler: ghc-7.6.3
84+
compilerKind: ghc
85+
compilerVersion: 7.6.3
86+
setup-method: hvr-ppa
5287
allow-failure: false
5388
- compiler: ghc-7.4.2
89+
compilerKind: ghc
90+
compilerVersion: 7.4.2
91+
setup-method: hvr-ppa
5492
allow-failure: false
5593
fail-fast: false
5694
steps:
5795
- name: apt
5896
run: |
5997
apt-get update
60-
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common
61-
apt-add-repository -y 'ppa:hvr/ghc'
62-
apt-get update
63-
apt-get install -y $CC cabal-install-3.4
98+
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
99+
if [ "${{ matrix.setup-method }}" = ghcup ]; then
100+
mkdir -p "$HOME/.ghcup/bin"
101+
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
102+
chmod a+x "$HOME/.ghcup/bin/ghcup"
103+
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER"
104+
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
105+
else
106+
apt-add-repository -y 'ppa:hvr/ghc'
107+
apt-get update
108+
apt-get install -y "$HCNAME"
109+
mkdir -p "$HOME/.ghcup/bin"
110+
curl -sL https://downloads.haskell.org/ghcup/0.1.17.3/x86_64-linux-ghcup-0.1.17.3 > "$HOME/.ghcup/bin/ghcup"
111+
chmod a+x "$HOME/.ghcup/bin/ghcup"
112+
"$HOME/.ghcup/bin/ghcup" install cabal 3.6.2.0
113+
fi
64114
env:
65-
CC: ${{ matrix.compiler }}
115+
HCKIND: ${{ matrix.compilerKind }}
116+
HCNAME: ${{ matrix.compiler }}
117+
HCVER: ${{ matrix.compilerVersion }}
66118
- name: Set PATH and environment variables
67119
run: |
68120
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
69-
echo "LANG=C.UTF-8" >> $GITHUB_ENV
70-
echo "CABAL_DIR=$HOME/.cabal" >> $GITHUB_ENV
71-
echo "CABAL_CONFIG=$HOME/.cabal/config" >> $GITHUB_ENV
72-
HCDIR=$(echo "/opt/$CC" | sed 's/-/\//')
73-
HCNAME=ghc
74-
HC=$HCDIR/bin/$HCNAME
75-
echo "HC=$HC" >> $GITHUB_ENV
76-
echo "HCPKG=$HCDIR/bin/$HCNAME-pkg" >> $GITHUB_ENV
77-
echo "HADDOCK=$HCDIR/bin/haddock" >> $GITHUB_ENV
78-
echo "CABAL=/opt/cabal/3.4/bin/cabal -vnormal+nowrap" >> $GITHUB_ENV
121+
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
122+
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
123+
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
124+
HCDIR=/opt/$HCKIND/$HCVER
125+
if [ "${{ matrix.setup-method }}" = ghcup ]; then
126+
HC=$HOME/.ghcup/bin/$HCKIND-$HCVER
127+
echo "HC=$HC" >> "$GITHUB_ENV"
128+
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
129+
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
130+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
131+
else
132+
HC=$HCDIR/bin/$HCKIND
133+
echo "HC=$HC" >> "$GITHUB_ENV"
134+
echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV"
135+
echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV"
136+
echo "CABAL=$HOME/.ghcup/bin/cabal-3.6.2.0 -vnormal+nowrap" >> "$GITHUB_ENV"
137+
fi
138+
79139
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
80-
echo "HCNUMVER=$HCNUMVER" >> $GITHUB_ENV
81-
echo "ARG_TESTS=--enable-tests" >> $GITHUB_ENV
82-
echo "ARG_BENCH=--enable-benchmarks" >> $GITHUB_ENV
83-
echo "HEADHACKAGE=false" >> $GITHUB_ENV
84-
echo "ARG_COMPILER=--$HCNAME --with-compiler=$HC" >> $GITHUB_ENV
85-
echo "GHCJSARITH=0" >> $GITHUB_ENV
140+
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
141+
echo "ARG_TESTS=--enable-tests" >> "$GITHUB_ENV"
142+
echo "ARG_BENCH=--enable-benchmarks" >> "$GITHUB_ENV"
143+
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
144+
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
145+
echo "GHCJSARITH=0" >> "$GITHUB_ENV"
86146
env:
87-
CC: ${{ matrix.compiler }}
147+
HCKIND: ${{ matrix.compilerKind }}
148+
HCNAME: ${{ matrix.compiler }}
149+
HCVER: ${{ matrix.compilerVersion }}
88150
- name: env
89151
run: |
90152
env
@@ -145,7 +207,8 @@ jobs:
145207
- name: generate cabal.project
146208
run: |
147209
PKGDIR_binary_orphans="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/binary-orphans-[0-9.]*')"
148-
echo "PKGDIR_binary_orphans=${PKGDIR_binary_orphans}" >> $GITHUB_ENV
210+
echo "PKGDIR_binary_orphans=${PKGDIR_binary_orphans}" >> "$GITHUB_ENV"
211+
rm -f cabal.project cabal.project.local
149212
touch cabal.project
150213
touch cabal.project.local
151214
echo "packages: ${PKGDIR_binary_orphans}" >> cabal.project

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.2
2+
3+
- Add `Solo` instance
4+
15
# 1.0.1
26

37
- Fix `MonadFail` instances shim

binary-orphans.cabal

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cabal-version: 1.12
22
name: binary-orphans
3-
version: 1.0.1
4-
x-revision: 5
3+
version: 1.0.2
54
synopsis: Compatibility package for binary; provides instances
65
category: Data, Binary, Parsing, Compatibility
76
description:
@@ -27,6 +26,7 @@ tested-with:
2726
|| ==8.8.4
2827
|| ==8.10.4
2928
|| ==9.0.1
29+
|| ==9.2.1
3030

3131
extra-source-files: CHANGELOG.md
3232

@@ -40,18 +40,21 @@ library
4040
exposed-modules: Data.Binary.Orphans
4141
other-extensions: CPP
4242
build-depends:
43-
base >=4.5 && <4.16
44-
, binary >=0.5.1.0 && <0.6 || >=0.7.1.0 && <0.8 || >=0.8.3.0 && <0.8.9
43+
base >=4.5 && <4.17
44+
, binary >=0.5.1.0 && <0.6 || >=0.7.1.0 && <0.8 || >=0.8.3.0 && <0.8.10
4545
, transformers >=0.3.0.0 && <0.7
4646

4747
if !impl(ghc >=7.10)
4848
build-depends: nats >=1.1.2 && <1.2
4949
build-depends: void >=0.7.3 && <0.8
5050

5151
if !impl(ghc >=8.0)
52-
build-depends: fail ==4.9.*
52+
build-depends: fail >=4.9 && <4.10
5353
build-depends: semigroups >=0.18.5 && <0.19.2
5454

55+
if !impl(ghc >=9.2)
56+
build-depends: OneTuple >=0.3 && <0.4
57+
5558
test-suite binary-orphans-test
5659
default-language: Haskell2010
5760
type: exitcode-stdio-1.0
@@ -62,6 +65,7 @@ test-suite binary-orphans-test
6265
base
6366
, binary
6467
, binary-orphans
68+
, OneTuple >=0.3 && <0.4
6569
, QuickCheck >=2.13.1 && <2.15
6670
, quickcheck-instances >=0.3.21 && <0.4
6771
, tagged >=0.8.6 && <0.8.7

src/Data/Binary/Orphans.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ import Data.Void (Void, absurd)
2828
import GHC.Fingerprint (Fingerprint (..))
2929
import Numeric.Natural (Natural)
3030

31+
#if MIN_VERSION_base(4,16,0)
32+
import Data.Tuple (Solo (..))
33+
#else
34+
import Data.Tuple.Solo (Solo (..))
35+
#endif
36+
3137
-------------------------------------------------------------------------------
3238
-- binary-0.7.1.0
3339
-------------------------------------------------------------------------------
@@ -323,3 +329,11 @@ instance Binary a => Binary (Identity a) where
323329
#endif
324330

325331
#endif
332+
333+
-------------------------------------------------------------------------------
334+
-- future-binary
335+
-------------------------------------------------------------------------------
336+
337+
instance Binary a => Binary (Solo a) where
338+
put (Solo x) = put x
339+
get = fmap Solo get

test/Tests.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Data.Binary.Orphans ()
66
import Data.Monoid (Sum)
77
import Data.Proxy
88
import Data.Semigroup (Min (..))
9+
import Data.Tuple.Solo (Solo (..))
910
import Numeric.Natural (Natural)
1011
import Test.QuickCheck (Property, (===))
1112
import Test.QuickCheck.Instances ()
@@ -20,6 +21,7 @@ tests = testGroup "Roundtrip"
2021
[ testProperty "Natural" $ roundtrip (Proxy :: Proxy Natural)
2122
, testProperty "Sum Int" $ roundtrip (Proxy :: Proxy (Sum Int))
2223
, testProperty "Min Int" $ roundtrip (Proxy :: Proxy (Min Int))
24+
, testProperty "Solo Int" $ roundtrip (Proxy :: Proxy (Solo Int))
2325
]
2426

2527
roundtrip :: (Eq a, Show a, Binary a) => Proxy a -> a -> Property

0 commit comments

Comments
 (0)