Added various general helper functions to the Utils module
This commit is contained in:
parent
a5c02f36ec
commit
bacc3115e9
|
@ -103,9 +103,6 @@ data Monad m => GraphLabelFuncs m label = GLF {
|
||||||
,labelScopeOut :: A.Specification -> m label
|
,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
|
-- | Builds the instructions to send to GraphViz
|
||||||
makeFlowGraphInstr :: (Monad m, Show a) => FlowGraph m a -> String
|
makeFlowGraphInstr :: (Monad m, Show a) => FlowGraph m a -> String
|
||||||
makeFlowGraphInstr = graphviz'
|
makeFlowGraphInstr = graphviz'
|
||||||
|
|
|
@ -106,3 +106,20 @@ combineCompare (EQ:os) = combineCompare os
|
||||||
-- | Maps two functions over members of a pair
|
-- | Maps two functions over members of a pair
|
||||||
transformPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b)
|
transformPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b)
|
||||||
transformPair f g (x,y) = (f x, g y)
|
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
|
||||||
|
|
|
@ -34,6 +34,7 @@ import qualified Data.Set as Set
|
||||||
import qualified AST as A
|
import qualified AST as A
|
||||||
import FlowAlgorithms
|
import FlowAlgorithms
|
||||||
import FlowGraph
|
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:
|
-- In Rain, Deref can't nest with Dir in either way, so this doesn't need to be a recursive type:
|
||||||
data Var =
|
data Var =
|
||||||
|
@ -374,10 +375,6 @@ findReachDef graph startNode
|
||||||
modifiedInput :: Map.Map Var (Set.Set Node)
|
modifiedInput :: Map.Map Var (Set.Set Node)
|
||||||
modifiedInput = (maybe id (nodeLabelToMapInsert n) $ lab graph n) inputVal
|
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
|
-- | 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)
|
mergeMultiMaps :: (Ord k, Ord a) => Map.Map k (Set.Set a) -> Map.Map k (Set.Set a) -> Map.Map k (Set.Set a)
|
||||||
mergeMultiMaps = Map.unionWith (Set.union)
|
mergeMultiMaps = Map.unionWith (Set.union)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user