Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy sampler is not a monad? #212

Open
turion opened this issue Oct 12, 2022 · 1 comment
Open

Lazy sampler is not a monad? #212

turion opened this issue Oct 12, 2022 · 1 comment

Comments

@turion
Copy link
Collaborator

turion commented Oct 12, 2022

Is the lazy sampler actually a monad? I believe it doesn't satisfy the monad laws:

ghci> import Control.Monad.Bayes.Sampler.Lazy
ghci> import System.Random
ghci> g <- newStdGen
ghci> let prog = (Control.Monad.Bayes.Class.random :: Control.Monad.Bayes.Sampler.Lazy.Sampler Double) >>= return
ghci> let prog' = (Control.Monad.Bayes.Class.random :: Control.Monad.Bayes.Sampler.Lazy.Sampler Double)
ghci> runSampler prog $ randomTree g
0.7318877896125477
ghci> runSampler prog' $ randomTree g
0.23172949590893044

Even worse, it's not even a functor with liftM:

ghci> runSampler (liftM id prog) $ randomTree g
0.6649028878458447

This is because depending on how we construct the program, the random number generator gets split or not. But this is not coassociative (there are no nontrivial comonoids in Haskell) and thus the monad laws don't hold.

@reubenharry
Copy link
Contributor

This sounds like an issue to take up with Sam Staton and his students - this code comes from their work on LazyPPL, and since they're into denotational semantics, this seems like a thing they'd care about. I've previously been in touch with them, so definitely something we could just ask them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants