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

Question: Free density monad vs. state density monad #263

Open
turion opened this issue Mar 9, 2023 · 3 comments
Open

Question: Free density monad vs. state density monad #263

turion opened this issue Mar 9, 2023 · 3 comments

Comments

@turion
Copy link
Collaborator

turion commented Mar 9, 2023

In the docs we describe two density monads (https://github.com/tweag/monad-bayes/blob/master/docs/docs/usage.md#density):

Monad-bayes offers two implementations, in Control.Monad.Bayes.Density.State and Control.Monad.Bayes.Density.Free. The first is slow but easy to understand, the second is more sophisticated, but faster.

In the code we have both variants, but only the free density monad (supposedly faster) is used outside this part:

mhTrans :: MonadDistribution m => (Weighted (State.Density m)) a -> Trace a -> m (Trace a)

@reubenharry @idontgetoutmuch Is it fair to say that realistically, we will only ever use the free density monad, and the state density monad is only for didactic purposes? If so, I'd vote for removing the corresponding code and simplifying the leftovers, and keep the state density only in the docs, which would be slightly adapted.

@reubenharry
Copy link
Contributor

That is fair to say, and I don't oppose that.

@idontgetoutmuch
Copy link
Member

I tried to use the state version instead of the free version but get an unsatisfied constraint. If here:

https://github.com/tweag/monad-bayes/blob/free-vs-state/src/Control/Monad/Bayes/Traced/Basic.hs#L26

you import import Control.Monad.Bayes.Density.State (Density) then I get

src/Control/Monad/Bayes/Traced/Basic.hs:60:19: error:
    • Could not deduce (MonadDistribution Identity)
        arising from a use of ‘random’
      from the context: MonadDistribution m
        bound by the instance declaration
        at src/Control/Monad/Bayes/Traced/Basic.hs:59:10-60
    • In the first argument of ‘Traced’, namely ‘random’
      In the expression: Traced random (fmap singleton random)
      In an equation for ‘random’:
          random = Traced random (fmap singleton random)
   |
60 |   random = Traced random (fmap singleton random)

Can anyone explain what is happening? I presume at some point the state version worked.

@reubenharry
Copy link
Contributor

Hmm, actually not entirely sure it ever worked. This is perhaps irrelevant since it looks like we'll remove this. The error looks familiar though.

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

3 participants