Compositional Generator Equivalence (Extended Version)
Pith reviewed 2026-06-26 09:19 UTC · model grok-4.3
The pith
Any sound and complete compositional semantics for Hedgehog must match its sampling semantics, which blocks common optimizations, but a restricted arrow-calculus version admits a compositional distribution semantics.
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
Core claim
Hedgehog's distribution semantics is non-compositional; any sound and complete compositional semantics for the full language is necessarily equivalent to its sampling semantics; and the arrow-calculus restriction Hedgehog→ possesses a compositional distribution semantics while remaining expressive enough for generators of practical interest.
What carries the argument
Hedgehog→, the arrow-calculus restriction whose distribution semantics is compositional and therefore supports equivalence proofs between generators.
If this is right
- Common generator rewrites cannot be justified by compositional reasoning inside the original Hedgehog language.
- Equivalence proofs between generators become possible inside Hedgehog→ because its distribution semantics is compositional.
- The sampling semantics remains available for implementation while the distribution semantics can be used for high-level reasoning in the restricted language.
- Optimizations that preserve the distribution semantics can now be validated compositionally for the class of generators expressible in Hedgehog→.
Where Pith is reading between the lines
- The same tension between compositionality and granularity may appear in other property-based testing frameworks that expose similar generator combinators.
- Tooling that automatically rewrites generators could be built on top of the compositional distribution semantics once the restriction is adopted.
- Users may still write full Hedgehog generators and then mechanically translate the parts that need equivalence proofs into the arrow fragment.
Load-bearing premise
The distribution semantics correctly models how users reason about generators and the arrow-calculus restriction is still expressive enough to write generators of practical interest.
What would settle it
A counter-example generator that is expressible in Hedgehog→ yet cannot be given a compositional distribution semantics, or a concrete optimization whose correctness cannot be proved even inside Hedgehog→.
Figures
read the original abstract
Property-based testing (PBT) is a powerful technique for software verification that relies on random input generators and "shrinking" processes to find and minimize counterexamples to executable specifications called properties. While optimizing these generators is crucial for testing efficiency, formally justifying such optimizations is currently difficult because existing languages lack a compositional semantics that is coarse-grained enough for high-level reasoning. In this paper, we first provide a formal account of the syntax and semantics of Hedgehog, a popular PBT framework. We demonstrate that Hedgehog's distribution semantics - which models how users typically reason about generators - is non-compositional. Furthermore, we prove that any sound and complete compositional semantics for Hedgehog must necessarily be equivalent to its sampling semantics, which is too fine-grained to justify common program optimizations. To resolve this dilemma, we introduce Hedgehog$^\rightarrow$, a restricted version of the language based on the arrow calculus, and prove that Hedgehog$^\rightarrow$ possesses a compositional distribution semantics. We evaluate Hedgehog$^\rightarrow$ through a Haskell implementation and show that it remains expressive enough to capture generators of practical interest, while providing the formal foundation needed for compositional generator equivalence proofs.
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper provides a formal account of the syntax and semantics of Hedgehog, a property-based testing framework. It proves that Hedgehog's distribution semantics is non-compositional, that any sound and complete compositional semantics must coincide with the sampling semantics (which is too fine-grained for justifying optimizations), and that the restricted Hedgehog→ language (based on the arrow calculus) admits a compositional distribution semantics. It backs this with a Haskell implementation claimed to retain practical expressiveness for generators of interest.
Significance. If the central claims hold, the work supplies a formal foundation for compositional reasoning about generator equivalence in PBT, directly addressing the difficulty of justifying optimizations. The non-compositionality result and the arrow-calculus restriction are technically substantive; the implementation evaluation provides evidence that the restriction does not eliminate practical use cases. Machine-checked proofs or fully reproducible artifacts would further strengthen the contribution.
minor comments (3)
- §3 (or wherever the non-compositionality proof appears): clarify whether the counterexample relies on specific features of the distribution semantics definition or holds more generally for any probabilistic semantics with the given monadic structure.
- The Haskell implementation section: include a brief comparison table of expressiveness (e.g., number of generators from the original Hedgehog suite that can be directly ported) to make the practicality claim easier to assess.
- Notation for the arrow calculus embedding: ensure that the translation from Hedgehog→ programs to arrows is defined equationally in one place so readers can verify preservation of the distribution semantics.
Simulated Author's Rebuttal
We thank the referee for their positive assessment of the paper and for recommending minor revision. The report does not list any specific major comments under the MAJOR COMMENTS section.
Circularity Check
No circularity: formal proofs rest on independent definitions and theorems
full rationale
The paper defines syntax, sampling semantics, and distribution semantics for Hedgehog from first principles, then proves non-compositionality and the forced equivalence of any sound/complete compositional semantics to the sampling semantics via explicit theorems. Hedgehog→ is introduced as an arrow-calculus restriction with its own compositional semantics proved separately. No step reduces a claimed result to a fitted parameter, self-definition, or load-bearing self-citation; all derivations are self-contained against the stated formal model and external Haskell implementation.
Axiom & Free-Parameter Ledger
axioms (1)
- standard math Standard properties of the arrow calculus for composing computations
Reference graph
Works this paper leans on
-
[1]
1995.Domain theory
Samson Abramsky and Achim Jung. 1995.Domain theory. Oxford University Press, Inc., USA, 1–168. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. 2006.Compilers: Principles, Techniques, and Tools (2nd Edition). Addison-Wesley Longman Publishing Co., Inc., USA. Emanuele Bandini and Roberto Segala
1995
-
[2]
InFM 2009: Formal Methods, Ana Cavalcanti and Dennis R
Unifying Probability with Nondeterminism. InFM 2009: Formal Methods, Ana Cavalcanti and Dennis R. Dams (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 467–482. Koen Claessen and John Hughes
2009
-
[3]
QuickCheck: a lightweight tool for random testing of Haskell programs. InProceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00), Montreal, Canada, September 18-21, 2000, Martin Odersky and Philip Wadler (Eds.). ACM, New York, NY, 268–279. doi:10.1145/351240.351266 Koen Claessen, Michal Palka, Nicholas Smallbone,...
-
[4]
Finding race conditions in Erlang with QuickCheck and PULSE.SIGPLAN Not.44, 9 (Aug. 2009), 149–160. doi:10.1145/1631687. 1596574 Ryan Culpepper and Andrew Cobb
-
[5]
Contextual Equivalence for Probabilistic Programs with Continuous Random Variables and Scoring. InProgramming Languages and Systems: 26th European Symposium on Programming, ESOP 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, April 22–29, 2017, Proceedings(Uppsala, Sweden). Springer-Ver...
-
[6]
Decomposing Probabilistic Lambda-Calculi. InFoundations of Software Science and Computation Structures: 23rd International Conference, FOSSACS 2020, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2020, Dublin, Ireland, April 25–30, 2020, Proceedings(Dublin, Ireland). Springer-Verlag, Berlin, Heidelberg, 136–156. d...
-
[7]
InProceedings of the 16th ACM SIGPLAN International Haskell Symposium, Haskell 2023, Seattle, W A, USA, September 8-9, 2023, Trevor L
falsify: Internal Shrinking Reimagined for Haskell. InProceedings of the 16th ACM SIGPLAN International Haskell Symposium, Haskell 2023, Seattle, W A, USA, September 8-9, 2023, Trevor L. McDonell and Niki Vazou (Eds.). ACM, , Vol. 1, No. 1, Article . Publication date: June
2023
-
[8]
doi:10.1145/3609026.3609733 Emil Eriksson
30 Anthony Vandikas, Kiarash Sotoudeh, and Marsha Chechik New York, NY, 97–109. doi:10.1145/3609026.3609733 Emil Eriksson
-
[9]
In2019 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS)
Lambda Calculus and Probabilistic Computation. In2019 34th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS). 1–13. doi:10.1109/LICS.2019.8785699 Andrew Farmer, Andy Gill, Ed Komp, and Neil Sculthorpe
-
[10]
InProceedings of the 2012 Haskell Symposium(Copenhagen, Denmark) (Haskell ’12)
The HERMIT in the machine: a plugin for the interactive transformation of GHC core language programs. InProceedings of the 2012 Haskell Symposium(Copenhagen, Denmark) (Haskell ’12). Association for Computing Machinery, New York, NY, USA, 1–12. doi:10.1145/2364506.2364508 Jeremy Gibbons and Ralf Hinze
-
[11]
Just do it: simple monadic equational reasoning.SIGPLAN Not.46, 9 (Sept. 2011), 2–14. doi:10.1145/2034574.2034777 Harrison Goldstein, Samantha Frohlich, Meng Wang, and Benjamin C Pierce
-
[12]
Proceedings of the ACM on Programming Languages7, ICFP (2023), 322–355
Reflecting on Random Generation. Proceedings of the ACM on Programming Languages7, ICFP (2023), 322–355. Chris Heunen, Ohad Kammar, Sam Staton, and Hongseok Yang
2023
-
[13]
Generalising monads to arrows.Sci. Comput. Program.37, 1–3 (May 2000), 67–111. doi:10.1016/S0167- 6423(99)00023-4 John Hughes
-
[14]
Programming with arrows. InProceedings of the 5th International Conference on Advanced Functional Programming(Tartu, Estonia)(AFP’04). Springer-Verlag, Berlin, Heidelberg, 73–129. doi:10.1007/11546382_2 Robert Krook, Nicholas Smallbone, Bo Joel Svensson, and Koen Claessen
-
[15]
Sam Lindley, Philip Wadler, and Jeremy Yallop
QuickerCheck: Implementing and Evaluating a Parallel Run-Time for QuickCheck(IFL 2023). Sam Lindley, Philip Wadler, and Jeremy Yallop
2023
-
[16]
The arrow calculus.J. Funct. Program.20, 1 (2010), 51–69. doi:10.1017/ S095679680999027X Jason Lyngle
2010
-
[17]
Open Source Softw
Hypothesis: A new approach to property-based testing.J. Open Source Softw. 4, 43 (2019),
2019
-
[18]
doi:10.21105/JOSS.01891 Conor Mcbride and Ross Paterson
-
[19]
Applicative programming with effects.J. Funct. Program.18, 1 (Jan. 2008), 1–13. doi:10.1017/S0956796807006326 Michael Mislove, Joël Ouaknine, and James Worrell
-
[20]
Eugenio Moggi
Axioms for probability and nondeterminism.Electronic Notes in Theoretical Computer Science96 (2004), 7–28. Eugenio Moggi
2004
-
[21]
Notions of Computation and Monads.Inf. Comput.93, 1 (1991), 55–92. doi:10.1016/0890-5401(91)90052- 4 Ross Paterson
-
[22]
A new notation for arrows.SIGPLAN Not.36, 10 (Oct. 2001), 229–240. doi:10.1145/507669.507664 Gordon D. Plotkin
-
[23]
LCF Considered as a Programming Language.Theor. Comput. Sci.5, 3 (1977), 223–255. doi:10.1016/ 0304-3975(77)90044-5 Jaro Reinders
1977
-
[24]
InProceedings of the 17th ACM SIGPLAN International Haskell Symposium(Milan, Italy)(Haskell 2024)
Higher Order Patterns for Rewrite Rules. InProceedings of the 17th ACM SIGPLAN International Haskell Symposium(Milan, Italy)(Haskell 2024). Association for Computing Machinery, New York, NY, USA, 14–26. doi:10.1145/3677999.3678275 Cynthia Richey, Joseph W. Cutler, Harrison Goldstein, and Benjamin C. Pierce
-
[25]
Jacob Stanley
Fail Faster: Staging and Fast Randomness for High-Performance PBT.Proceedings of the ACM on Programming Languages(2026). Jacob Stanley
2026
-
[26]
Commutative Semantics for Probabilistic Programming. InProgramming Languages and Systems: 26th European Symposium on Programming, ESOP 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, April 22–29, 2017, Proceedings(Uppsala, Sweden). Springer-Verlag, Berlin, Heidelberg, 855–879. doi:10.10...
-
[27]
frasertweedale.github.io/blog-fp/posts/2020- 03-31-quickcheck-hedgehog.html#shrinking-performance Matthijs Vákár, Ohad Kammar, and Sam Staton
Migrating from QuickCheck to Hedgehog: mixed results. frasertweedale.github.io/blog-fp/posts/2020- 03-31-quickcheck-hedgehog.html#shrinking-performance Matthijs Vákár, Ohad Kammar, and Sam Staton
2020
-
[28]
[VMA19] Andrea Vezzosi, Anders M¨ ortberg, and Andreas Abel
A domain theory for statistical probabilistic programming.Proc. ACM Program. Lang.3, POPL, Article 36 (Jan. 2019), 29 pages. doi:10.1145/3290349 Daniele Varacca and Glynn Winskel
-
[29]
Distributing probability over non-determinism.Mathematical structures in computer science16, 1 (2006), 87–113. , Vol. 1, No. 1, Article . Publication date: June 2026
2006
discussion (0)
Sign in with ORCID, Apple, or X to comment. Anyone can read and Pith papers without signing in.