tweag / monad-bayes

A library for probabilistic programming in Haskell.
MIT License
408 stars 62 forks source link

SMC2 not exported, thus not really usable? #180

Closed turion closed 2 years ago

turion commented 2 years ago

Looking at https://hackage.haskell.org/package/monad-bayes-0.1.1.0/docs/Control-Monad-Bayes-Inference-SMC2.html, it seems that to use this inference method, I have to supply a function of type b -> S (P (SMC2 m)) a, but the type SMC2 and its constructors are not exported. It seems to me that this is thus not usable.

reubenharry commented 2 years ago

Ah, but SMC2 is a MonadSample instance. Here's an example from the tests of how to run smc2:

population $ smc2 0 100 100 100 random (normal 0)

The whole idea of monad-bayes is that you write programs of type MonadInfer m => m X, which various different inference algorithms then specialize. In this case, you are supplying a MonadSample m => m Double and a MonadSample m => Double -> m Double, rather than anything concretely in SMC2. In fact, it's intentional not to expose SMC2

turion commented 2 years ago

Ah, ok. It's still hard to discover this fact, because since the type SMC2 is not exported, its haddocks are not displayed on hackage, so one cannot know that MonadSample SMC2.

reubenharry commented 2 years ago

Ah, that's a good point. To be honest, SMC2 was complicated enough that I didn't get to the point of making documentation or examples for it, as I did with the others. But I agree that's a problem - let me see if I can find a good solution, maybe by adding comments to the hackage docs

turion commented 2 years ago

How about exporting the type SMC2 without exporting the constructor? Then people can only create values of type SMC2 a by using its instances, but its haddocks are there.

turion commented 2 years ago

Plus, it appears on the hoogle and hackage searches!

reubenharry commented 2 years ago

Excellent idea, let me do that!

reubenharry commented 2 years ago

Resolved