probability 0.2.7 → 0.2.8
raw patch · 8 files changed
+25/−103 lines, 8 filesdep ~containersdep ~randomdep ~transformers
Dependency ranges changed: containers, random, transformers, utility-ht
Files
- Changes.md +8/−0
- ToDo +0/−3
- probability.cabal +4/−9
- src-fail/before-4.13/Numeric/Probability/Either.hs +0/−37
- src-fail/from-4.13/Numeric/Probability/Either.hs +0/−39
- src/Numeric/Probability/Distribution.hs +5/−7
- src/Numeric/Probability/Object.hs +3/−3
- src/Numeric/Probability/Transition.hs +5/−5
Changes.md view
@@ -1,5 +1,13 @@ # Change log for the `probability` package +## 0.2.8++ * `Numeric.Probability.Either` -> `Control.Monad.Trans.Except`+ Few functions exposed `EitherT` in their signatures,+ but `Numeric.Probability.Either` was private.+ Thus its removal should not be noticed by library users.++ ## 0.2.7 * support `random-1.2`
ToDo view
@@ -1,6 +1,3 @@-Numeric.Probability.Either -> Control.Monad.Trans.Except-- Object -> Experiment? Object
probability.cabal view
@@ -1,6 +1,6 @@ Cabal-Version: 1.24 Name: probability-Version: 0.2.7+Version: 0.2.8 License: BSD3 License-File: COPYRIGHT Author: Martin Erwig <erwig@eecs.oregonstate.edu>, Steve Kollmansberger@@ -29,7 +29,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/probability/- tag: 0.2.7+ tag: 0.2.8 Flag splitBase@@ -37,17 +37,13 @@ Library Build-Depends:- utility-ht >=0.0.6 && <0.1,- transformers >=0.0.1 && <0.6+ utility-ht >=0.0.12 && <0.1,+ transformers >=0.4 && <0.7 If flag(splitBase) Build-Depends: containers >=0.1 && <0.7, random >=1.0 && <1.3, base >=2 && <5- If impl(ghc>=8.8)- Hs-Source-Dirs: src-fail/from-4.13/- Else- Hs-Source-Dirs: src-fail/before-4.13/ Else Build-Depends: special-functors >=1.0 && <1.1,@@ -86,4 +82,3 @@ Numeric.Probability.Monad Numeric.Probability.PrintList Numeric.Probability.Show- Numeric.Probability.Either
− src-fail/before-4.13/Numeric/Probability/Either.hs
@@ -1,37 +0,0 @@-module Numeric.Probability.Either where--import Control.Monad.Instances ()--import Control.Applicative (Applicative, pure, (<*>), liftA2, )---newtype EitherT a m b = EitherT (m (Either a b))--instance Functor m => Functor (EitherT a m) where- fmap f (EitherT m) = EitherT $ fmap (fmap f) m--instance Applicative m => Applicative (EitherT a m) where- pure a = EitherT $ pure $ Right a- EitherT af <*> EitherT am =- EitherT $- liftA2 (\ef em ->- case ef of- Left b -> Left b- Right f ->- case em of- Left b -> Left b- Right m -> Right $ f m) af am--instance Monad m => Monad (EitherT a m) where- return a = EitherT $ return $ Right a- EitherT m >>= f = EitherT $ do- e <- m- case e of- Left b -> return $ Left b- Right a ->- case f a of- EitherT n -> n- fail s = EitherT $ fail s--throw :: Applicative m => a -> EitherT a m b-throw a = EitherT $ pure $ Left a
− src-fail/from-4.13/Numeric/Probability/Either.hs
@@ -1,39 +0,0 @@-module Numeric.Probability.Either where--import Control.Monad.Instances ()--import Control.Applicative (Applicative, pure, (<*>), liftA2, )---newtype EitherT a m b = EitherT (m (Either a b))--instance Functor m => Functor (EitherT a m) where- fmap f (EitherT m) = EitherT $ fmap (fmap f) m--instance Applicative m => Applicative (EitherT a m) where- pure a = EitherT $ pure $ Right a- EitherT af <*> EitherT am =- EitherT $- liftA2 (\ef em ->- case ef of- Left b -> Left b- Right f ->- case em of- Left b -> Left b- Right m -> Right $ f m) af am--instance Monad m => Monad (EitherT a m) where- return a = EitherT $ return $ Right a- EitherT m >>= f = EitherT $ do- e <- m- case e of- Left b -> return $ Left b- Right a ->- case f a of- EitherT n -> n--instance MonadFail m => MonadFail (EitherT a m) where- fail s = EitherT $ fail s--throw :: Applicative m => a -> EitherT a m b-throw a = EitherT $ pure $ Left a
src/Numeric/Probability/Distribution.hs view
@@ -5,6 +5,7 @@ import Numeric.Probability.Show (showR) import qualified Numeric.Probability.Shape as Shape +import qualified Control.Functor.HT as FuncHT import Control.Applicative (Applicative(..)) import Control.Monad (liftM, liftM2, join, ) @@ -121,9 +122,7 @@ -- ** Auxiliary functions for constructing and working with distributions-lift :: (Num prob) =>- ([(a,prob)] -> [(a,prob)]) ->- T prob a -> T prob a+lift :: (Num prob) => ([(a,prob)] -> [(b,prob)]) -> T prob a -> T prob b lift f = Cons . f . decons size :: T prob a -> Int@@ -358,10 +357,9 @@ select :: (Num prob, Ord prob, Ord a) => (prob -> Bool) -> T prob a -> T prob (Select a)-select condp (Cons d) =+select condp = lift $ \d -> let (d1,d2) = Map.partition condp $ Map.fromListWith (+) d- in Cons $- (Other, Fold.sum d2) :+ in (Other, Fold.sum d2) : List.map (mapFst Case) (Map.toAscList d1) fromFreqs :: (Fractional prob) => [(a,prob)] -> T prob a@@ -375,7 +373,7 @@ mapMaybe :: (Fractional prob) => (a -> Maybe b) -> T prob a -> T prob b mapMaybe f =- fromFreqs . Maybe.mapMaybe (\(x,p) -> fmap (flip (,) p) $ f x) . decons+ fromFreqs . Maybe.mapMaybe (FuncHT.mapFst f) . decons -- | selecting from distributions
src/Numeric/Probability/Object.hs view
@@ -20,10 +20,10 @@ import qualified Numeric.Probability.Distribution as Dist import qualified Numeric.Probability.Random as Rnd import qualified Numeric.Probability.Shape as Shape-import qualified Numeric.Probability.Either as PE import qualified Data.List as List +import qualified Control.Monad.Trans.Except as ME import Control.Monad (liftM, ) @@ -37,9 +37,9 @@ instance Fractional prob => C prob (Dist.T prob) where fromFrequencies = Dist.fromFreqs -instance C prob obj => C prob (PE.EitherT b obj) where+instance C prob obj => C prob (ME.ExceptT b obj) where fromFrequencies =- PE.EitherT . liftM Right . fromFrequencies+ ME.ExceptT . liftM Right . fromFrequencies
src/Numeric/Probability/Transition.hs view
@@ -3,7 +3,7 @@ import qualified Numeric.Probability.Distribution as Dist -import qualified Numeric.Probability.Either as PE+import qualified Control.Monad.Trans.Except as ME import qualified Data.Map as Map @@ -75,13 +75,13 @@ any action after a 'go' is ignored. -} fix :: (Num prob, Ord a, Ord b) =>- ((a -> PE.EitherT a (Dist.T prob) b) ->- (a -> PE.EitherT a (Dist.T prob) b)) ->+ ((a -> ME.ExceptT a (Dist.T prob) b) ->+ (a -> ME.ExceptT a (Dist.T prob) b)) -> Dist.T prob a -> Dist.T prob b fix f = untilLeft $ \a ->- case f PE.throw a of- PE.EitherT m -> fmap (either Right Left) m+ case f ME.throwE a of+ ME.ExceptT m -> fmap (either Right Left) m -- * Spreading changes into transitions