Changeset 12775

Show
Ignore:
Timestamp:
03.11.2009 15:03:01 (3 weeks ago)
Author:
maeder
Message:

hlinted

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Common/Lib/Rel.hs

    r12774 r12775  
    128128-- | make relation irreflexive 
    129129irreflex :: Ord a => Rel a -> Rel a 
    130 irreflex (Rel m) = Rel $ rmNull $ Map.mapWithKey (Set.delete) m 
     130irreflex (Rel m) = Rel $ rmNull $ Map.mapWithKey Set.delete m 
    131131 
    132132-- | compute strongly connected components for a transitively closed relation 
     
    146146 
    147147setToMap :: Ord a => Set.Set a -> Map.Map a a 
    148 setToMap s = Map.fromDistinctAscList $ 
    149              List.map (\ a -> (a, a)) $ Set.toList s 
     148setToMap = Map.fromDistinctAscList . List.map (\ a -> (a, a)) . Set.toList 
    150149 
    151150{- | transitive reduction (minimal relation with the same transitive closure) 
     
    188187map :: (Ord a, Ord b) => (a -> b) -> Rel a -> Rel b 
    189188map f (Rel m) = Rel $ Map.foldWithKey 
    190     ( \ a v -> Map.insertWith Set.union (f a) $ Set.map f v) Map.empty m 
     189    ( \ a -> Map.insertWith Set.union (f a) . Set.map f) Map.empty m 
    191190 
    192191-- | Restriction of a relation under a set 
     
    204203-- | convert a set of ordered pairs to a relation 
    205204fromSet :: (Ord a) => Set.Set (a, a) -> Rel a 
    206 fromSet s = fromAscList $ Set.toList s 
     205fromSet = fromAscList . Set.toList 
    207206 
    208207-- | convert a sorted list of ordered pairs to a relation 
     
    223222   between 1 and the second value that is output. -} 
    224223toPrecMap :: Ord a =>  Rel a -> (Map.Map a Int, Int) 
    225 toPrecMap r = foldl ( \ (m1, c) s -> let n = c + 1 in 
     224toPrecMap = foldl ( \ (m1, c) s -> let n = c + 1 in 
    226225                    (Set.fold ( \ i -> Map.insert i n) m1 s, n)) 
    227                  (Map.empty, 0) $ topSort r 
     226                 (Map.empty, 0) . topSort 
    228227 
    229228topSortDAG :: Ord a => Rel a -> [Set.Set a] 
     
    254253    else let Rel im = irreflex r 
    255254             mr = elemsSet im Set.\\ Map.keysSet im 
    256          in if Set.null mr then Map.keysSet $ Map.filterWithKey (\ k v -> 
    257                                            Set.singleton k == v) m 
     255         in if Set.null mr then Map.keysSet $ Map.filterWithKey 
     256                ((==) . Set.singleton) m 
    258257            else mr 
    259258 
     
    287286    let (a, b) = Set.deleteFindMin c 
    288287        (m, d) = Set.deleteFindMax c 
    289     in insert m a $ foldr ( \ (x, y) -> insert x y) (delete a a r) $ 
     288    in insert m a $ foldr (uncurry insert) (delete a a r) $ 
    290289       zip (Set.toList d) (Set.toList b) 
    291290 
     
    296295haveCommonLeftElem :: (Ord a) => a -> a -> Rel a -> Bool 
    297296haveCommonLeftElem t1 t2 = 
    298     Map.fold(\ e rs -> rs || (t1 `Set.member` e && 
    299                               t2 `Set.member` e)) False . toMap 
     297    Map.fold(\ e -> (|| Set.member t1 e && Set.member t2 e)) False . toMap 
    300298 
    301299-- | partitions a set into a list of disjoint non-empty subsets 
     
    327325    where iso x y = member x y rel && member y x rel 
    328326          check s = Set.null s || 
    329                   Set.fold (\y rs -> rs && 
    330                                      not (haveCommonLeftElem x y rel)) True s' 
     327                  Set.fold (\ y -> 
     328                            (&& not (haveCommonLeftElem x y rel))) True s' 
    331329                  && check s' 
    332330              where (x, s') = Set.deleteFindMin s