@@ -40,7 +40,6 @@ module Control.Monad.Bayes.Population
40
40
where
41
41
42
42
import Control.Applicative (Alternative )
43
- import Control.Applicative.List qualified as ApplicativeListT
44
43
import Control.Arrow (second )
45
44
import Control.Monad (MonadPlus , replicateM )
46
45
import Control.Monad.Bayes.Class
@@ -49,6 +48,7 @@ import Control.Monad.Bayes.Class
49
48
MonadMeasure ,
50
49
factor ,
51
50
)
51
+ import Control.Monad.Bayes.Population.Applicative qualified as Applicative
52
52
import Control.Monad.Bayes.Weighted
53
53
( WeightedT ,
54
54
applyWeight ,
@@ -70,6 +70,11 @@ import Numeric.Log qualified as Log
70
70
import Prelude hiding (all , sum )
71
71
72
72
-- | A collection of weighted samples, or particles.
73
+ --
74
+ -- This monad transformer is internally represented as a free monad,
75
+ -- which means that each layer of its computation contains a collection of weighted samples.
76
+ -- These can be flattened with 'flatten',
77
+ -- but the result is not a monad anymore.
73
78
newtype PopulationT m a = PopulationT { getPopulationT :: WeightedT (FreeT [] m ) a }
74
79
deriving newtype (Functor , Applicative , Alternative , Monad , MonadIO , MonadPlus , MonadDistribution , MonadFactor , MonadMeasure )
75
80
@@ -278,12 +283,12 @@ hoist ::
278
283
PopulationT n a
279
284
hoist f = PopulationT . Weighted. hoist (hoistFreeT f) . getPopulationT
280
285
281
- -- | Flatten all layers of the free structure
282
- flatten :: (Monad m ) => PopulationT m a -> ApplicativeListT . PopulationT m a
283
- flatten = ApplicativeListT . fromWeightedList . runPopulationT
286
+ -- | Flatten all layers of the free structure.
287
+ flatten :: (Monad m ) => PopulationT m a -> Applicative . PopulationT m a
288
+ flatten = Applicative . fromWeightedList . runPopulationT
284
289
285
290
-- | Create a population from a single layer of branching computations.
286
291
--
287
292
-- Similar to 'fromWeightedListT'.
288
- single :: (Monad m ) => ApplicativeListT . PopulationT m a -> PopulationT m a
289
- single = fromWeightedList . ApplicativeListT . runPopulationT
293
+ single :: (Monad m ) => Applicative . PopulationT m a -> PopulationT m a
294
+ single = fromWeightedList . Applicative . runPopulationT
0 commit comments