packages feed

kuifje 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+23/−11 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Language.Kuifje.Distribution: point :: Ord a => a -> Dist a
+ Language.Kuifje.Distribution: type Hyper a = Dist (Dist a)
+ Language.Kuifje.Semantics: average :: Dist Rational -> Rational
- Language.Kuifje.Distribution: join :: Ord a => Dist (Dist a) -> Dist a
+ Language.Kuifje.Distribution: join :: Ord a => Hyper a -> Dist a
- Language.Kuifje.Semantics: condEntropy :: (Dist a -> Rational) -> Dist (Dist a) -> Rational
+ Language.Kuifje.Semantics: condEntropy :: (Dist a -> Rational) -> Hyper a -> Rational
- Language.Kuifje.Semantics: type a ~~> b = Dist a -> Dist (Dist b)
+ Language.Kuifje.Semantics: type a ~~> b = Dist a -> Hyper b

Files

ChangeLog.md view
@@ -1,8 +1,12 @@ # Revision history for kuifje +## 0.1.2.0 -- 2019-09-10++* Added some helper functions and type declarations.+ ## 0.1.1.0 -- 2019-09-06 -* Updated dependency boundaries and initial changelog entry+* Updated dependency boundaries and initial changelog entry.  ## 0.1.0.0  -- 2019-09-06 
kuifje.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                kuifje-version:             0.1.1.0+version:             0.1.2.0 synopsis:            A Quantitative Information Flow aware programming language. description:         A prototype for a Quantitative Information Flow aware programming language. 
src/Language/Kuifje/Distribution.hs view
@@ -15,6 +15,9 @@ -- | Distribution data type. newtype Dist a = D { runD :: Map a Prob } +-- | Type alias for hyper-distributions.+type Hyper a = Dist (Dist a)+ -- | Top-level fmap function for distributions. fmap :: (Ord b) => (a -> b) -> Dist a -> Dist b fmap f dx = dx >>= (return . f)@@ -24,12 +27,16 @@ return :: (Ord a) => a -> Dist a return x = D $ singleton x 1 +-- | Alias for return function.+point :: Ord a => a -> Dist a+point = return+ -- | Top-level bind function for distributions. (>>=) :: (Ord b) => Dist a -> (a -> Dist b) -> Dist b d >>= f = D $ fromListWith (+) [(y, p * q) | (x, p) <- toList $ runD d, (y, q) <- toList $ runD (f x)]  -- | Top-level join function for distributions.-join :: (Ord a) => Dist (Dist a) -> Dist a+join :: (Ord a) => Hyper a -> Dist a join x = x >>= id  instance Ord a => Eq (Dist a) where
src/Language/Kuifje/Semantics.hs view
@@ -5,13 +5,13 @@ module Language.Kuifje.Semantics where  import Prelude hiding (return, fmap, (>>=))-import Data.Map.Strict (fromListWith, toList, elems)+import Data.Map.Strict (fromListWith, toList, elems, mapWithKey)  import Language.Kuifje.Distribution import Language.Kuifje.Syntax  -- | Hyper-distribution type synonym.-type a ~~> b = Dist a -> Dist (Dist b)+type a ~~> b = Dist a -> Hyper b  -- | Bind with reduction applied to the input distribution. (=>>) :: (Ord b) => Dist a -> (a -> Dist b) -> Dist b@@ -64,7 +64,7 @@         f' ws = let dpws = D $ fromListWith (+) [(s, p) | ((ws', s), p) <- toList $ runD dp, ws' == ws]                 in D $ fromListWith (+) [(s, p / weight dpws) | (s, p) <- toList $ runD dpws] -    multiply :: (Ord s) => (Dist o, o -> Dist s) -> Dist (Dist s)+    multiply :: (Ord s) => (Dist o, o -> Dist s) -> Hyper s     multiply (d, f') = fmap f' d  -- | Calculate Bayes Vulnerability for a distribution.@@ -73,8 +73,9 @@  -- | Based on an entropy function for distributions, calculate the -- average entropy for a hyper-distribution.-condEntropy :: (Dist a -> Rational) -> Dist (Dist a) -> Rational-condEntropy e m = average (fmap e m) where-  -- | Average a distribution of Rationals.-  average :: Dist Rational -> Rational-  average d = sum [r * p | (r, p) <- toList $ runD d]+condEntropy :: (Dist a -> Rational) -> Hyper a -> Rational+condEntropy e m = average (fmap e m)++-- | Average a distribution of Rationals.+average :: Dist Rational -> Rational+average = sum . mapWithKey (*) . runD