diff --git a/common/FlowGraph.hs b/common/FlowGraph.hs index 97ad1fa..a601aef 100644 --- a/common/FlowGraph.hs +++ b/common/FlowGraph.hs @@ -103,9 +103,6 @@ data Monad m => GraphLabelFuncs m label = GLF { ,labelScopeOut :: A.Specification -> m label } -(>>*) :: Monad m => m a -> (a -> b) -> m b -(>>*) v f = v >>= (return . f) - -- | Builds the instructions to send to GraphViz makeFlowGraphInstr :: (Monad m, Show a) => FlowGraph m a -> String makeFlowGraphInstr = graphviz' diff --git a/common/Utils.hs b/common/Utils.hs index 74ade88..5966972 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -106,3 +106,20 @@ combineCompare (EQ:os) = combineCompare os -- | Maps two functions over members of a pair transformPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b) transformPair f g (x,y) = (f x, g y) + +-- | Pipes a monadic return through a non-monadic transformation function: +(>>*) :: Monad m => m a -> (a -> b) -> m b +(>>*) v f = v >>= (return . f) + +-- | Folds a list of modifier functions into a single function +foldFuncs :: [a -> a] -> a -> a +foldFuncs = foldl (.) id + +-- | Like the reflection of map. Instead of one function and multiple data, +-- we have multiple functions and one data. +applyAll :: a -> [a -> b] -> [b] +applyAll x = map (\f -> f x) + +-- | Like concat applied after mapM (or the monadic version of concatMap). +concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b] +concatMapM f x = mapM f x >>* concat diff --git a/transformations/RainUsageCheck.hs b/transformations/RainUsageCheck.hs index 1f3df6d..8002809 100644 --- a/transformations/RainUsageCheck.hs +++ b/transformations/RainUsageCheck.hs @@ -34,6 +34,7 @@ import qualified Data.Set as Set import qualified AST as A import FlowAlgorithms import FlowGraph +import Utils -- In Rain, Deref can't nest with Dir in either way, so this doesn't need to be a recursive type: data Var = @@ -373,10 +374,6 @@ findReachDef graph startNode modifiedInput :: Map.Map Var (Set.Set Node) modifiedInput = (maybe id (nodeLabelToMapInsert n) $ lab graph n) inputVal - - -- | Folds a list of modifier functions into a single function - foldFuncs :: [a -> a] -> a -> a - foldFuncs = foldl (.) id -- | Merges two "multi-maps" (maps to sets) using union mergeMultiMaps :: (Ord k, Ord a) => Map.Map k (Set.Set a) -> Map.Map k (Set.Set a) -> Map.Map k (Set.Set a)