From 3dba2a478b0d545157e0a80b7b19d06b5cf08271 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Wed, 23 May 2018 13:13:20 +0200 Subject: [PATCH] HLint --- app/Main.hs | 10 +++++----- src/Environment.hs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index a2609a3..f7e1e30 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -119,11 +119,11 @@ main = do probs <- randomRs (0.2,0.7) <$> newStdGen let emptyPlants = replicate 100 emptyPlant poisonedTree = poisonTree ds randomCompounds - poisonCompounds = foldMap (\(a,b) -> if a > 0.5 then [(b,a)] else []) $ poisonedTree + poisonCompounds = foldMap (\(a,b) -> [(b,a) | a > 0.5]) poisonedTree predators <- generatePredators 0.5 poisonedTree let env = exampleEnvironment (getTreeSize randomCompounds) (generateEnzymeFromTree randomCompounds) (zip predators probs) poisonCompounds printEnvironment env - writeFile "poison.twopi" $ generateDotFromPoisonTree "poison" 0.5 $ poisonedTree + writeFile "poison.twopi" $ generateDotFromPoisonTree "poison" 0.5 poisonedTree putStr "\ESC[?1049h" loop 200 emptyPlants env putStrLn "Simulation ended. Press key to exit." @@ -143,14 +143,14 @@ generatePredators threshold t = do ps <- mapM generatePredators' $ getSubTrees t return $ filter ((/= []) . irresistance) $ concat ps -- filter out predators that are resistant to everything because this does not make sense in our model. where - generatePredators' :: (EnzymeTree s (Double, Compound)) -> IO [Predator] + generatePredators' :: EnzymeTree s (Double, Compound) -> IO [Predator] generatePredators' t = do -- not fully resistant to t, but fully resistant to everything in ts - let comps = foldMap (\(a,b) -> if a > threshold then [(a,b)] else []) t + let comps = foldMap (\(a,b) -> [(a,b) | a > threshold]) t amount <- randomRIO (0,length comps + 1) :: IO Int forM [1..amount] $ \_ -> do impact <- randomRIO (0.2,0.7) rands <- randoms <$> newStdGen - let unresists = foldMap (\((a,b),r) -> if r*2 < a then [b] else []) $ zip comps rands + let unresists = foldMap (\((a,b),r) -> [b | r*2 < a]) $ zip comps rands return $ Predator unresists impact printEnvironment :: Environment -> IO () diff --git a/src/Environment.hs b/src/Environment.hs index 36d0bd7..817e1dc 100644 --- a/src/Environment.hs +++ b/src/Environment.hs @@ -194,7 +194,7 @@ deterPredators cs = do appearingPredators = fmap fst . filter (\((_,p),r) -> p > r) $ zip ps ds -- assign one probability to each predator, filter those who appear, throw random data away again. -- appearingPredators is now a sublist of ps. deter :: Predator -> Double - -- multiply (toxicity of t with 100% effectiveness at l| for all toxins t | and t not in p's irresistance-list) + -- multiply (toxicity of t with 100% effectiveness at l| for all toxins t; and t in p's irresistance-list) deter p = product [1 - min 1 (cs ! fromEnum t / l) | (t,l) <- ts, t `elem` irresistance p] -- multiply (probability of occurence * intensity of destruction / probability to deter predator | for all predators) return $ product ([min 1 ((1-prob) * fitnessImpact p / deter p) | (p,prob) <- appearingPredators])