summaryrefslogtreecommitdiff
path: root/src/Sequence
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-12-02 13:26:55 +0100
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-12-02 13:26:55 +0100
commitcc4e079be3d0e918119c08301595460c3e91ef3c (patch)
tree753c48c922253c9b1ff6fe2d00f1b6d8898bc973 /src/Sequence
parent7ecbf4f5c7bd0c3c2f92559a2313274b6d075e6c (diff)
download2017-01-16_17:13:37-cc4e079be3d0e918119c08301595460c3e91ef3c.tar
2017-01-16_17:13:37-cc4e079be3d0e918119c08301595460c3e91ef3c.tar.gz
2017-01-16_17:13:37-cc4e079be3d0e918119c08301595460c3e91ef3c.tar.bz2
2017-01-16_17:13:37-cc4e079be3d0e918119c08301595460c3e91ef3c.tar.xz
2017-01-16_17:13:37-cc4e079be3d0e918119c08301595460c3e91ef3c.zip
Print all applicable values
Diffstat (limited to 'src/Sequence')
-rw-r--r--src/Sequence/Formula.hs4
-rw-r--r--src/Sequence/Utils.hs1
2 files changed, 5 insertions, 0 deletions
diff --git a/src/Sequence/Formula.hs b/src/Sequence/Formula.hs
index 2ac1210..878ec7f 100644
--- a/src/Sequence/Formula.hs
+++ b/src/Sequence/Formula.hs
@@ -5,6 +5,7 @@ module Sequence.Formula
5 , (:<:)(..), Context(..), ctx 5 , (:<:)(..), Context(..), ctx
6 , evalFormula, evalFormula' 6 , evalFormula, evalFormula'
7 , findDistribution, findDistribution' 7 , findDistribution, findDistribution'
8 , findAverage
8 , val 9 , val
9 , d, z 10 , d, z
10 , Table, table 11 , Table, table
@@ -137,6 +138,9 @@ evalFormula' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (ev
137findDistribution' :: (MonadIO m, sInput :<: lInput, MonadState lInput m, Ord a) => [String] -> FormulaM sInput a -> m (Map a Rational) 138findDistribution' :: (MonadIO m, sInput :<: lInput, MonadState lInput m, Ord a) => [String] -> FormulaM sInput a -> m (Map a Rational)
138findDistribution' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (findDistribution promptPref) formula =<< get 139findDistribution' promptPref formula = uncurry (<$) . over _2 put . swap =<< flip (findDistribution promptPref) formula =<< get
139 140
141findAverage :: (MonadIO m, sInput :<: lInput, MonadState lInput m, Real a) => [String] -> FormulaM sInput a -> m Rational
142findAverage promptPref formula = sum . map (\(val, prob) -> toRational val * prob) . Map.toList <$> findDistribution' promptPref formula
143
140val :: Traversal' input (Formula input) -> [String] -> Bool -> Formula input 144val :: Traversal' input (Formula input) -> [String] -> Bool -> Formula input
141val answer prompt keepResult = do 145val answer prompt keepResult = do
142 gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..}) 146 gets (Set.member prompt) >>= bool (modify $ Set.insert prompt) (modify (Set.delete prompt) >> throwError Question{..})
diff --git a/src/Sequence/Utils.hs b/src/Sequence/Utils.hs
index f51bcd8..9f03ca7 100644
--- a/src/Sequence/Utils.hs
+++ b/src/Sequence/Utils.hs
@@ -7,6 +7,7 @@ module Sequence.Utils
7 , toName, toDesc 7 , toName, toDesc
8 , outputLogged 8 , outputLogged
9 , scaleTimer 9 , scaleTimer
10 , statAccessors
10 , Argument(..) 11 , Argument(..)
11 , Completion(..) 12 , Completion(..)
12 , module Sequence.Utils.Ask 13 , module Sequence.Utils.Ask