Skip to content

Commit decbd40

Browse files
committed
typed-protocols: support QuickCheck 2.15
1 parent 8d1d7dd commit decbd40

File tree

5 files changed

+101
-3
lines changed

5 files changed

+101
-3
lines changed

typed-protocols/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Revision history for typed-protocols
22

3-
## 1.1.0.0 -- 05.08.2025
3+
## 1.1.0.1 -- 2025-10-14
4+
5+
* Support QuickCheck <= 2.15
6+
7+
## 1.1.0.0 -- 2025-08-03
48

59
### Breaking changes
610

typed-protocols/properties/Network/TypedProtocol/Codec/Properties.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE QuantifiedConstraints #-}
23

34
module Network.TypedProtocol.Codec.Properties
@@ -37,6 +38,9 @@ import Network.TypedProtocol.Codec
3738
import Network.TypedProtocol.Core
3839

3940
import Test.QuickCheck
41+
#if !MIN_VERSION_QuickCheck(2,16,0)
42+
import Test.QuickCheck.Monoids.Compat
43+
#endif
4044

4145

4246
-- | The 'CodecF' round-trip property: decode after encode gives the same

typed-protocols/properties/Network/TypedProtocol/Stateful/Codec/Properties.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE QuantifiedConstraints #-}
23

34
module Network.TypedProtocol.Stateful.Codec.Properties
@@ -13,6 +14,9 @@ import Network.TypedProtocol.Core
1314
import Network.TypedProtocol.Stateful.Codec
1415

1516
import Test.QuickCheck
17+
#if !MIN_VERSION_QuickCheck(2,16,0)
18+
import Test.QuickCheck.Monoids.Compat
19+
#endif
1620

1721

1822
-- | The 'Codec' round-trip property: decode after encode gives the same
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ExistentialQuantification #-}
3+
{-# LANGUAGE ExplicitNamespaces #-}
4+
{-# LANGUAGE PackageImports #-}
5+
{-# LANGUAGE PatternSynonyms #-}
6+
7+
-- | Monoids using `.&&.` and `.||.`.
8+
--
9+
-- They satisfy monoid laws with respect to the `isSuccess` unless one is using
10+
-- `checkCoverage` (see test for a counterexample).
11+
--
12+
module Test.QuickCheck.Monoids.Compat
13+
#if !MIN_VERSION_QuickCheck(2,16,0)
14+
( type Every
15+
, All(Every, getEvery, ..)
16+
, type Some
17+
, Any(Some, getSome, ..)
18+
#else
19+
( All (..)
20+
, Any (..)
21+
, Every (..)
22+
, Some (..)
23+
#endif
24+
) where
25+
26+
import Data.List.NonEmpty as NonEmpty
27+
import Data.Semigroup (Semigroup (..))
28+
import Test.QuickCheck
29+
30+
-- | Conjunction monoid build with `.&&.`.
31+
--
32+
-- Use `property @All` as an accessor which doesn't leak
33+
-- existential variables.
34+
--
35+
data All = forall p. Testable p => All { getAll :: p }
36+
37+
#if !MIN_VERSION_QuickCheck(2,16,0)
38+
type Every = All
39+
40+
pattern Every :: ()
41+
=> Testable p
42+
=> p
43+
-> All
44+
pattern Every { getEvery } = All getEvery
45+
#endif
46+
47+
instance Testable All where
48+
property (All p) = property p
49+
50+
instance Semigroup All where
51+
All p <> All p' = All (p .&&. p')
52+
sconcat = All . conjoin . NonEmpty.toList
53+
54+
instance Monoid All where
55+
mempty = All True
56+
mconcat = All . conjoin
57+
58+
59+
-- | Disjunction monoid build with `.||.`.
60+
--
61+
-- Use `property @Any` as an accessor which doesn't leak
62+
-- existential variables.
63+
--
64+
data Any = forall p. Testable p => Any { getAny :: p }
65+
66+
#if !MIN_VERSION_QuickCheck(2,16,0)
67+
type Some = Any
68+
69+
pattern Some :: ()
70+
=> Testable p
71+
=> p
72+
-> Any
73+
pattern Some { getSome } = Any getSome
74+
#endif
75+
76+
instance Testable Any where
77+
property (Any p) = property p
78+
79+
instance Semigroup Any where
80+
Any p <> Any p' = Any (p .||. p')
81+
sconcat = Any . disjoin . NonEmpty.toList
82+
83+
instance Monoid Any where
84+
mempty = Any False
85+
mconcat = Any . disjoin

typed-protocols/typed-protocols.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: typed-protocols
3-
version: 1.1.0.0
3+
version: 1.1.0.1
44
synopsis: A framework for strongly typed protocols
55
description: A robust session type framework which supports protocol pipelining.
66
Haddocks are published [here](https://input-output-hk.github.io/typed-protocols/)
@@ -54,9 +54,10 @@ library codec-properties
5454
visibility: public
5555
exposed-modules: Network.TypedProtocol.Codec.Properties
5656
Network.TypedProtocol.Stateful.Codec.Properties
57+
other-modules: Test.QuickCheck.Monoids.Compat
5758
build-depends: base >=4.12 && <4.22,
5859
typed-protocols:{stateful, typed-protocols},
59-
QuickCheck >= 2.16
60+
QuickCheck
6061
hs-source-dirs: properties
6162
default-extensions: GADTs
6263
ImportQualifiedPost

0 commit comments

Comments
 (0)