Tainted 0.1.0.1 → 0.1.0.2
raw patch · 3 files changed
+81/−2 lines, 3 files
Files
- Tainted.cabal +13/−2
- examples/TaintedExample.hs +30/−0
- examples/TransExample.hs +38/−0
Tainted.cabal view
@@ -2,9 +2,8 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: Tainted-version: 0.1.0.1+version: 0.1.0.2 synopsis: Tainted type, and associated operations-description: Tainted type, and associated operations homepage: https://github.com/RossMeikleham/Tainted license: BSD3 license-file: LICENSE@@ -18,6 +17,18 @@ .gitignore .travis.yml README.md+ examples/TaintedExample.hs+ examples/TransExample.hs++description: + A Tainted type contains either a clean or dirty value. Values which are+ clean stay clean as long as an operation performed on them results+ in a clean value. If combined with a dirty value, the value becomes+ tainted as dirty and remains that way through further operations.+ + This package contains implementations of the Tainted Monad as well as+ TaintedT (the Tainted Monad Transformer), as well as examples of using+ each of them. source-repository head
+ examples/TaintedExample.hs view
@@ -0,0 +1,30 @@+module TaintedExample where++import Data.Tainted+import Control.Monad++data Expr = + Number (Tainted Int)+ | Add Expr Expr+ + deriving Show++pure1 = Number (Clean 3)+pure2 = Number (Clean 7)+impure1 = Number (Dirty 5)++expr1 = Add pure1 pure2+expr2 = Add impure1 pure1+expr3 = Add pure1 (Add impure1 pure2) ++--Evaluate expression as much as Possible+evalExpr :: Expr -> Expr+evalExpr (Number n) = Number n+evalExpr (Add e1 e2) = + case (evalExpr e1, evalExpr e2) of+ (Number i, Number j) -> Number $ liftM2 (+) i j+ (x, y) -> Add x y++reducedExpr1 = evalExpr expr1+reducedExpr2 = evalExpr expr2+reducedExpr3 = evalExpr expr3
+ examples/TransExample.hs view
@@ -0,0 +1,38 @@+module TaintTransformerExample where++import Data.Tainted+import Control.Monad.Trans.Tainted+import Control.Monad.State++type TaintedState a b = TaintedT (State a) b++doStuff :: Int -> (TaintedState Int Int) -> Tainted Int+doStuff n f = evalState (runTainted f) n+ ++f :: TaintedState Int Int+f = do+ x <- lift get+ return $ x + 6+++g :: TaintedState Int Int+g = do+ x <- lift get+ y <- hoistTainted $ Dirty 6+ return $ x + y+++h :: TaintedState Int Int+h = do+ x <- lift get+ lift $ put (x + 1)+ y <- hoistTainted $ Dirty 7+ z <- lift get+ return $ x + y + z+++ex1 = doStuff 5 f +ex2 = doStuff 5 g +ex3 = doStuff 5 h+