REVIEW 3 major objections 6 minor 57 references
Functional probabilistic programming for scalable Bayesian modelling
T0 review · 3 major / 6 minor · reviewed 2026-08-14 · deepseek-v4-flash
Pith's one-line read Embedding a probabilistic programming language in functional Scala makes Bayesian models ordinary monadic values, so hierarchical models can be built from simpler model code and inferred by one generic Hamiltonian Monte Carlo sampler.
desk verdict A clear, honest tutorial on monadic probabilistic programming in Scala, but the title and the 'decoupling' claim overstate what Rainier actually delivers; worth publishing as pedagogy after revision, not as research. read the letter →
The pith
A machine-rendered reading of the paper's core claim, the machinery that carries it, and where it could break.
The reading
What carries the argument
The load-bearing object is the probability monad, realised in Scala as a RandomVariable monad for model construction and a Rand monad for sampling; flatMap composes conditional distributions by the law of total probability. Around this monad, the embedded DSL builds a compute graph for the un-normalised log-posterior, compiles that graph into a function from parameter values to a scalar and a gradient, and hands it to Hamiltonian Monte Carlo. The monad is what does the work: it makes models composable values, provides the for-comprehension syntax familiar to Scala programmers, and unifies density evaluation and sampling under one interface.
What would settle it
Run the paper's hierarchical random-effects example at ten times the data size and compare effective sample size per computing second against a compiled general-purpose probabilistic programming system on the same model; a large gap, or failure to complete, would falsify the scalability claim. A second decisive test is to write a model containing a discrete latent variable and show that the embedded DSL either cannot express it or cannot run Hamiltonian Monte Carlo on it without rewriting the model.
Extended reading notes
Core claim
On its own terms, the paper's central discovery is that embedding a statistical modelling DSL in a statically typed functional language gives probabilistic programs the same compositionality as ordinary functional programs. The key move is to represent distributions as monads, so the Scala for-comprehension lets a user express priors and likelihoods in a readable model-specification syntax while the model remains a value that can be stored, passed to functions, and rebuilt from smaller models. The same monadic structure carries the two pieces of machinery inference needs: a monad for random sampling and a compute-graph representation of the un-normalised log-posterior whose gradient is produced by reverse-mode automatic differentiation. Because inference reads only the log-posterior and its gradient, changing or tuning the inference algorithm does not require rewriting the model.
Load-bearing premise
The claim that the approach scales rests on three small illustrative examples, with no benchmark showing what happens on larger models or on models with discrete parameters.
Editorial extensions
If this is right
- Model code written for one problem can be reused inside larger models, as shown by building the random-effects model from the linear-regression model.
- Practitioners no longer need to derive gradients or write MCMC updates; a generic Hamiltonian Monte Carlo sampler consumes the automatically differentiated log-posterior.
- Standard collection operations such as groupBy and traverse can assemble hierarchical models from per-class submodels.
- Because models are ordinary values, the same code can be used in development and in production, reducing translation errors between the two.
- Switching inference algorithms, or tuning leapfrog step size and number of steps, can happen without altering the model specification.
Reading between the lines
- A natural next test is whether the same monadic design scales to larger datasets through parallel and distributed collections; the paper sketches this but provides no benchmark.
- The discrete-parameter limitation is inherited from Hamiltonian Monte Carlo, so a fuller scalability story would need a companion path such as marginalisation or a separate sampler for discrete latent variables.
- The modular reuse shown for random effects should extend naturally to other hierarchical structures, such as time-series or spatial models, because composition is the primitive rather than a prebuilt model library.
Signed reviews
Editorial analysis
A structured set of objections, weighed in public.
Referee Report
Summary. The paper presents an introductory account of how functional programming concepts, particularly monads, can support embedded probabilistic programming languages for Bayesian modelling. It reviews category theory (functors, natural transformations, monads), probability monads, Hamiltonian Monte Carlo, and automatic differentiation, and illustrates the ideas using the Scala library Rainier. Three example models are given: a linear model, a Gaussian mixture model, and a hierarchical random-effects model. The abstract and conclusion make two broad claims: that model specification is decoupled from inference so that any generic inference algorithm can be used, and that functional programming in Scala is a suitable, powerful approach for developing scalable Bayesian modelling.
Significance. If the claims were fully supported, the paper would make a useful contribution by demonstrating how functional abstractions enable modular, composable probabilistic programs. The tutorial material is accurate at an introductory level, and the paper helpfully connects category theory with a practical implementation. The repository with runnable code is a strength. However, the two headline claims are not established by the evidence provided: the architecture embeds HMC's differentiability requirement into the model representation, undermining the decoupling claim, and the empirical examples contain no scalability evaluation. The paper is best read as a tutorial or position paper, and its central claims require revision or substantial additional evidence.
major comments (3)
- [Abstract, §7, §9] The claim that 'model inference can be carried out using any generic inference algorithm' is in direct tension with the architecture presented in §7. Listing 2 defines `param` only for `Continuous` distributions, and §7 explicitly states that discrete distributions cannot be used as parameters in HMC since they cannot be differentiated. The compute graph exposes gradient functions with signature `Array[Double] => Array[Double]`, encoding HMC's differentiability requirement into the model representation itself. Thus the implemented system supports HMC-style gradient-based inference on continuous parameters, not arbitrary generic inference algorithms. The paper should either weaken the decoupling claim or demonstrate that the model representation can be consumed by multiple inference algorithms without rewriting the model code.
- [Title, §8] The title promises 'scalable Bayesian modelling', but the examples in §8 provide no scalability evidence: the linear model uses 1,000 observations, the mixture model uses 10,000 simulated observations, and no wall-clock times, memory usage, scaling curves, or comparisons with Stan or Pyro are reported. The paper also does not address known limitations of HMC for discrete parameters or highly correlated posteriors. The title and abstract should either be revised to avoid the scalability claim or the paper should include a proper empirical scaling evaluation.
- [§9] The conclusion states that 'it has been shown that functional programming in Scala is a suitable, powerful language for developing a probabilistic programming language as an embedded DSL.' The evidence consists of three small examples, all with continuous, differentiable parameters, and no comparison with alternative approaches or exploration of the limitations acknowledged in §7. This statement overstates the scope of what is demonstrated; it should be qualified to refer to continuous-parameter HMC-based modelling in the embedded DSL.
minor comments (6)
- [§1] In the sentence 'the likelihood and prior distributions for each parameter must is specified', the phrase 'must is specified' should be 'must be specified'.
- [§3.10] The sentence 'In order to generate a new number myGenerator must be given an initial value, which is the initial state of the of the random number generator' contains a duplicated 'of the' and should be edited.
- [§4] The phrase 'space of of all probability measures' contains a duplicated 'of'.
- [§8.1] The text refers to 'Listing 14' when describing the linear model code, but the actual listing is numbered 'Listing 4'. The cross-reference should be corrected.
- [§2.3] In the monad definition, `µ` is called 'multiplication (or counit)'. 'Counit' is the standard term for the counit of a comonad, not for monad multiplication; consider using 'multiplication' only.
- [§7, Listing 2] The `param` method is declared to return `RandomVariable[Real]` even though the trait is `Continuous[A]`; this is type-inconsistent for a general continuous distribution over a non-real space such as a vector. Clarify the intended type or restrict the trait appropriately.
Circularity Check
No significant circularity: the paper is an expository tutorial whose claims, including the decoupling statement, are not derived from fitted outputs or self-citation chains.
full rationale
The paper does not fit a parameter and then rename that fit as a prediction, and it does not derive any result from its own output. The Section 8 examples simulate data from known parameter values, run HMC, and compare posterior draws with those simulation values; this is a sanity check, not a predicted quantity obtained from fitted inputs. The Giry-monad foundations, HMC correctness, and chain-rule automatic differentiation are cited from independent external sources and are not used to justify the paper's own conclusions. The central claim that model specification is decoupled from inference is not circular: 'any generic inference algorithm' is asserted as a design goal, and the fact that the Rainier implementation only defines param for Continuous distributions and requires gradients for HMC (Section 7) is a limitation of the demonstration rather than a case where the conclusion is identical to the premise. Rainier is cited as existing open-source software, not as a self-citation supplying an unverified uniqueness theorem or ansatz. No equation in the paper is equivalent to its input by construction, so no circular step is present.
Assumptions & free parameters
assumptions (4)
- standard math Definitions of categories, functors, natural transformations, and monads (Section 2)
- standard math The Giry monad on measurable spaces provides a probability monad (Section 4)
- standard math HMC with leapfrog integration targets the correct stationary distribution (Section 5)
- standard math Automatic differentiation via dual numbers and reverse mode computes exact gradients (Section 6)
Cite this review
Pith. "Pith review of Functional probabilistic programming for scalable Bayesian modelling." pith.science (2026). https://pith.science/paper/QYNWVZLJ
@misc{pith2026190802062,
author = {Pith},
title = {Pith review of: Functional probabilistic programming for scalable Bayesian modelling},
year = {2026},
howpublished = {\url{https://pith.science/paper/QYNWVZLJ}},
note = {Machine review of arXiv:1908.02062}
}
read the original abstract
Bayesian inference involves the specification of a statistical model by a statistician or practitioner, with careful thought about what each parameter represents. This results in particularly interpretable models which can be used to explain relationships present in the observed data. Bayesian models are useful when an experiment has only a small number of observations and in applications where transparency of data driven decisions is important. Traditionally, parameter inference in Bayesian statistics has involved constructing bespoke MCMC (Markov chain Monte Carlo) schemes for each newly proposed statistical model. This results in plausible models not being considered since efficient inference schemes are challenging to develop or implement. Probabilistic programming aims to reduce the barrier to performing Bayesian inference by developing a domain specific language (DSL) for model specification which is decoupled from the parameter inference algorithms. This paper introduces functional programming principles which can be used to develop an embedded probabilistic programming language. Model inference can be carried out using any generic inference algorithm. In this paper Hamiltonian Monte Carlo (HMC) is used, an efficient MCMC method requiring the gradient of the un-normalised log-posterior, calculated using automatic differentiation. The concepts are illustrated using the Scala programming language.
Figures
Figures from the paper (6 more)
Reference graph
Works this paper leans on
-
[1]
M. Abadi, A. Agarwal, P. Barham, E. Brevdo, Z. Chen, C. Citro, G. S. Corrado, A. Davis, J. Dean, M. Devin, S. Ghemawat, I. Goodfellow, A. Harp, G. Irving, M. Isard, Y. Jia, R. Jozefowicz, L. Kaiser, M. Kudlur, J. Levenberg, D. Man\' e , R. Monga, S. Moore, D. Murray, C. Olah, M. Schuster, J. Shlens, B. Steiner, I. Sutskever, K. Talwar, P. Tucker, V. Vanho...
work page 2015
-
[2]
Apache. Apache Hadoop , 2018 a . URL https://hadoop.apache.org/
work page 2018
-
[3]
Apache Spark - Unified Analytics Engine for Big Data , 2018 b
Apache. Apache Spark - Unified Analytics Engine for Big Data , 2018 b . URL http://spark.apache.org
work page 2018
-
[4]
Y. F. Atchad \'e , J. S. Rosenthal, et al. On adaptive Markov chain Monte Carlo algorithms . Bernoulli, 11 0 (5): 0 815--828, 2005
work page 2005
-
[5]
S. Awodey. Category theory. Oxford University Press, New York, second edition, 2010
work page 2010
-
[6]
M. Barr and C. Wells. Category theory for computing science, volume 49. Prentice Hall New York, 1990
work page 1990
-
[7]
M. Betancourt. A conceptual introduction to Hamiltonian Monte Carlo . arXiv preprint arXiv:1701.02434, 2017
arXiv 2017
-
[8]
G. E. P. Box and M. E. Muller. A note on the generation of random normal deviates. Ann. Math. Statist., 29 0 (2): 0 610--611, 06 1958. doi:10.1214/aoms/1177706645. URL https://doi.org/10.1214/aoms/1177706645
arXiv 1958
Show all 57 references
-
[9]
Brin and L
S. Brin and L. Page. The anatomy of a large-scale hypertextual web search engine. Computer networks and ISDN systems, 30 0 (1-7): 0 107--117, 1998
1998
-
[10]
A. Bryant. Rainier: Bayesian inference in Scala , 2018. URL https://github.com/stripe/rainier/
2018
-
[11]
Carpenter, A
B. Carpenter, A. Gelman, M. Hoffman, D. Lee, B. Goodrich, M. Betancourt, M. A. Brubaker, J. Guo, P. Li, A. Riddell, et al. Stan: A probabilistic programming language. Journal of Statistical Software, 20 0 (2): 0 1--37, 2016
2016
-
[12]
Chiusano and R
P. Chiusano and R. Bjarnason. Functional programming in Scala . Manning Publications Co., 2014
2014
-
[13]
Culbertson and K
J. Culbertson and K. Sturtz. A categorical foundation for B ayesian probability. Applied Categorical Structures, 22 0 (4): 0 647--662, 2014
2014
-
[14]
Dean and S
J. Dean and S. Ghemawat. MapReduce: simplified data processing on large clusters . Communications of the ACM, 51 0 (1): 0 107--113, 2008
2008
-
[15]
Duane, A
S. Duane, A. D. Kennedy, B. J. Pendleton, and D. Roweth. Hybrid Monte Carlo . Physics letters B, 195 0 (2): 0 216--222, 1987
1987
-
[16]
E. Fredkin. Trie memory. Commun. ACM, 3 0 (9): 0 490--499, Sept. 1960. ISSN 0001-0782. doi:10.1145/367390.367400. URL http://doi.acm.org/10.1145/367390.367400
1960
-
[17]
Fritz and P
T. Fritz and P. Perrone. A probability monad as the colimit of spaces of finite samples. Technical Report arXiv:1712.05363, arXiv, 2017
2017 arXiv
-
[18]
M. Giry. A categorical approach to probability theory. In Categorical aspects of topology and analysis, pages 68--85. Springer, 1982
1982
-
[19]
W. K. Hastings. Monte Carlo sampling methods using Markov chains and their applications . Biometrika, 57 0 (1): 0 97--109, 1970
1970
-
[20]
Heunen, O
C. Heunen, O. Kammar, S. Staton, and H. Yang. A convenient category for higher-order probability theory. In 2017 32nd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), pages 1--12. IEEE, 2017
2017
-
[21]
M. D. Hoffman and A. Gelman. The No-U-turn sampler: adaptively setting path lengths in Hamiltonian Monte Carlo. Journal of Machine Learning Research, 15 0 (1): 0 1593--1623, 2014
2014
-
[22]
Huang, Z
G. Huang, Z. Liu, L. Van Der Maaten, and K. Q. Weinberger. Densely connected convolutional networks. In CVPR, volume 1, page 3, 2017
2017
-
[23]
B. Jacobs. From probability monads to commutative effectuses. Journal of Logical and Algebraic Methods in Programming, 94: 0 200--237, January 2018
2018
-
[24]
M. P. Jones and L. Duponcheel. Composing monads. Technical report, Technical Report YALEU/DCS/RR-1004, Department of Computer Science. Yale, 1993
1993
-
[25]
B. B. Khomtchouk, E. Weitz, P. D. Karp, and C. Wahlestedt. How the strengths of lisp-family languages facilitate building complex and flexible bioinformatics applications. Briefings in bioinformatics, 19 0 (3): 0 537--543, 2016
2016
-
[26]
Kiselyov, A
O. Kiselyov, A. Sabry, and C. Swords. Extensible effects: an alternative to monad transformers. In ACM SIGPLAN Notices, volume 48, pages 59--70. ACM, 2013
2013
-
[27]
Kucukelbir, D
A. Kucukelbir, D. Tran, R. Ranganath, A. Gelman, and D. M. Blei. Automatic differentiation variational inference. The Journal of Machine Learning Research, 18 0 (1): 0 430--474, 2017
2017
-
[28]
F. W. Lawvere. The category of probabilistic mappings, 1962. URL https://ncatlab.org/nlab/files/lawvereprobability1962.pdf
1962
-
[29]
Liang, P
S. Liang, P. Hudak, and M. Jones. Monad transformers and modular interpreters. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 333--343. ACM, 1995
1995
-
[30]
D. J. Lunn, A. Thomas, N. Best, and D. Spiegelhalter. WinBUGS-a Bayesian modelling framework: concepts, structure, and extensibility . Statistics and computing, 10 0 (4): 0 325--337, 2000
2000
-
[31]
O. Manzyuk. A simply typed -calculus of forward automatic differentiation. Electronic Notes in Theoretical Computer Science, 286: 0 257--272, 2012
2012
-
[32]
Matsumoto and T
M. Matsumoto and T. Nishimura. Mersenne twister: a 623-dimensionally equidistributed uniform pseudo-random number generator. ACM Transactions on Modeling and Computer Simulation (TOMACS), 8 0 (1): 0 3--30, 1998
1998
-
[33]
McBride and R
C. McBride and R. Paterson. Applicative programming with effects. Journal of functional programming, 18 0 (1): 0 1--13, 2008
2008
-
[34]
Metropolis, A
N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller, and E. Teller. Equation of state calculations by fast computing machines. The journal of chemical physics, 21 0 (6): 0 1087--1092, 1953
1953
-
[35]
Milewski
B. Milewski. Category theory for programmers. Blurb, 2018
2018
-
[36]
Narayanan, J
P. Narayanan, J. Carette, W. Romano, C. Shan, and R. Zinkov. Probabilistic inference by program transformation in hakaru (system description). In International Symposium on Functional and Logic Programming - 13th International Symposium, FLOPS 2016, Kochi, Japan, March 4-6, 20...
2016 doi
-
[37]
R. M. Neal et al. MCMC using Hamiltonian dynamics . Handbook of Markov Chain Monte Carlo, 2 0 (11), 2011
2011
-
[38]
Odersky, P
M. Odersky, P. Altherr, V. Cremet, B. Emir, S. Maneth, S. Micheloud, N. Mihaylov, M. Schinz, E. Stenman, and M. Zenger. An overview of the Scala programming language . Technical Report IC/2004/64, EPFL Lausanne, Switzerland, 2004
2004
-
[39]
S. Park, F. Pfenning, and S. Thrun. A probabilistic language based upon sampling functions, volume 40. ACM, 2005
2005
-
[40]
Paszke, S
A. Paszke, S. Gross, S. Chintala, G. Chanan, E. Yang, Z. DeVito, Z. Lin, A. Desmaison, L. Antiga, and A. Lerer. Automatic differentiation in PyTorch . In NIPS-W, 2017
2017
-
[41]
Plummer et al
M. Plummer et al. JAGS: A program for analysis of Bayesian graphical models using Gibbs sampling . In Proceedings of the 3rd international workshop on distributed statistical computing, volume 124. Vienna, Austria, 2003
2003
-
[42]
R: A Language and Environment for Statistical Computing
R Core Team . R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing, Vienna, Austria, 2019. URL https://www.R-project.org/
2019
-
[43]
Ramsey and A
N. Ramsey and A. Pfeffer. Stochastic lambda calculus and monads of probability distributions. In ACM SIGPLAN Notices, volume 37, pages 154--165. ACM, 2002
2002
-
[44]
G. O. Roberts and J. S. Rosenthal. Optimal scaling of discrete approximations to Langevin diffusions . Journal of the Royal Statistical Society: Series B (Statistical Methodology), 60 0 (1): 0 255--268, 1998
1998
-
[45]
G. O. Roberts, A. Gelman, W. R. Gilks, et al. Weak convergence and optimal scaling of random walk Metropolis algorithms . The annals of applied probability, 7 0 (1): 0 110--120, 1997
1997
-
[46]
\'S cibior, Z
A. \'S cibior, Z. Ghahramani, and A. D. Gordon. Practical probabilistic programming with monads. In ACM SIGPLAN Notices, volume 50, pages 165--176. ACM, 2015
2015
-
[47]
\'S cibior, O
A. \'S cibior, O. Kammar, and Z. Ghahramani. Functional programming for modular B ayesian inference. Proceedings of the ACM on Programming Languages, 2: 0 83, 2018 a
2018
-
[48]
\'S cibior, O
A. \'S cibior, O. Kammar, M. Vakar, S. Staton, H. Yang, Y. Cai, K. Ostermann, S. K. Moss, C. Heunen, and Z. Ghahramani. Denotational validation of higher-order B ayesian inference. Proc. ACM Prog. Lang., 2 0 (60), 2018 b
2018
-
[49]
S. Staton. Commutative semantics for probabilistic programming. In H. Yang, editor, Programming languages and systems, volume 10201 of ESOP 2017. Lecture notes in computer science, Berlin, Heidelberg, 2017. Springer
2017
-
[50]
Swierstra
W. Swierstra. Data types \`a la carte. Journal of functional programming, 18 0 (4): 0 423--436, 2008
2008
-
[51]
Tensorflow probability, 2018
TensorFlow. Tensorflow probability, 2018. URL https://www.tensorflow.org/probability/
2018
-
[52]
Pyro: Deep universal probabilistic programming with Python and PyTorch , 2018
Uber. Pyro: Deep universal probabilistic programming with Python and PyTorch , 2018. URL https://github.com/uber/pyro
2018
-
[53]
P. Wadler. Monads for functional programming. In International School on Advanced Functional Programming, pages 24--52. Springer, 1995
1995
-
[54]
F. Wang, X. Wu, G. Essertel, J. Decker, and T. Rompf. Demystifying differentiable programming: Shift/reset the penultimate backpropagator. arXiv preprint arXiv:1803.10228, 2018
2018 arXiv
-
[55]
N. Welsh. Differentiable Functional Programming , 2018. URL https://slideslive.ch/38908798/differentiable-functional-programming
2018
-
[56]
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016. ISBN 978-3-319-24277-4. URL https://ggplot2.tidyverse.org
2016
-
[57]
C. Wu, J. Stoehr, and C. P. Robert. Faster Hamiltonian Monte Carlo by Learning Leapfrog Scale . arXiv preprint arXiv:1810.04449, 2018
2018 arXiv
Reviewed August 14, 2026 · model on record in the stance chip above.
Discussion (0). Continue with ORCID to comment.