From 2a8e2dc95937c411aa93aa32f50538d8fafd18f1 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 23 Mar 2011 15:42:09 +0100
Subject: [PATCH] Fix some lint warnings in htools code

hlint gives more suggestions, but some make the code (IMHO) harder to
read.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 htools/Ganeti/HTools/Cluster.hs | 14 +++++---------
 htools/Ganeti/HTools/Loader.hs  |  4 ++--
 htools/Ganeti/HTools/Luxi.hs    |  2 +-
 htools/Ganeti/HTools/Rapi.hs    |  2 +-
 htools/Ganeti/HTools/Text.hs    |  2 +-
 5 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs
index ca7cfb2e1..4588e7700 100644
--- a/htools/Ganeti/HTools/Cluster.hs
+++ b/htools/Ganeti/HTools/Cluster.hs
@@ -515,10 +515,7 @@ checkMove nodes_idx disk_moves ini_tbl victims =
         tables = parMap rwhnf (checkInstanceMove nodes_idx disk_moves ini_tbl)
                  victims
         -- iterate over all instances, computing the best move
-        best_tbl =
-            foldl'
-            (\ step_tbl new_tbl -> compareTables step_tbl new_tbl)
-            ini_tbl tables
+        best_tbl = foldl' compareTables ini_tbl tables
         Table _ _ _ best_plc = best_tbl
     in if length best_plc == length ini_plc
        then ini_tbl -- no advancement
@@ -694,7 +691,7 @@ sortMGResults :: Group.List
              -> [(Gdx, AllocSolution)]
              -> [(Gdx, AllocSolution)]
 sortMGResults gl sols =
-    let extractScore = \(_, _, _, x) -> x
+    let extractScore (_, _, _, x) = x
         solScore (gdx, sol) = (Group.allocPolicy (Container.find gdx gl),
                                (extractScore . head . asSolutions) sol)
     in sortBy (comparing solScore) sols
@@ -837,8 +834,7 @@ tryMGEvac _ nl il ex_ndx =
           all_insts3
       results <- mapM (\(_, gnl, gil, idxs) -> tryEvac gnl gil idxs ex_ndx)
                  all_insts4
-      let sol = foldl' (\orig_sol group_sol ->
-                        sumAllocs orig_sol group_sol) emptySolution results
+      let sol = foldl' sumAllocs emptySolution results
       return $ annotateSolution sol
 
 -- | Recursively place instances on the cluster until we're out of space
@@ -1084,8 +1080,8 @@ instancePriGroup nl i =
 -- | Compute the list of badly allocated instances (split across node
 -- groups)
 findSplitInstances :: Node.List -> Instance.List -> [Instance.Instance]
-findSplitInstances nl il =
-  filter (not . isOk . instanceGroup nl) (Container.elems il)
+findSplitInstances nl =
+  filter (not . isOk . instanceGroup nl) . Container.elems
 
 -- | Splits a cluster into the component node groups
 splitCluster :: Node.List -> Instance.List ->
diff --git a/htools/Ganeti/HTools/Loader.hs b/htools/Ganeti/HTools/Loader.hs
index c17aba1c7..186c13383 100644
--- a/htools/Ganeti/HTools/Loader.hs
+++ b/htools/Ganeti/HTools/Loader.hs
@@ -7,7 +7,7 @@ has been loaded from external sources.
 
 {-
 
-Copyright (C) 2009, 2010 Google Inc.
+Copyright (C) 2009, 2010, 2011 Google Inc.
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -198,7 +198,7 @@ mergeData um extags exinsts cdata@(ClusterData _ nl il2 tags) =
       il4 = Container.map (filterExTags allextags .
                            updateMovable exinsts) il3
       nl2 = foldl' fixNodes nl (Container.elems il4)
-      nl3 = Container.map (\node -> Node.buildPeers node il4) nl2
+      nl3 = Container.map (flip Node.buildPeers il4) nl2
       node_names = map Node.name (Container.elems nl)
       inst_names = map Instance.name il
       common_suffix = longestDomain (node_names ++ inst_names)
diff --git a/htools/Ganeti/HTools/Luxi.hs b/htools/Ganeti/HTools/Luxi.hs
index 15dc6c329..a3855c5de 100644
--- a/htools/Ganeti/HTools/Luxi.hs
+++ b/htools/Ganeti/HTools/Luxi.hs
@@ -213,4 +213,4 @@ parseData (groups, nodes, instances, cinfo) = do
 -- | Top level function for data loading
 loadData :: String -- ^ Unix socket to use as source
          -> IO (Result ClusterData)
-loadData master = readData master >>= return . parseData
+loadData = fmap parseData . readData
diff --git a/htools/Ganeti/HTools/Rapi.hs b/htools/Ganeti/HTools/Rapi.hs
index f77e859ac..19aa817fb 100644
--- a/htools/Ganeti/HTools/Rapi.hs
+++ b/htools/Ganeti/HTools/Rapi.hs
@@ -182,4 +182,4 @@ parseData (group_body, node_body, inst_body, tags_body) = do
 -- | Top level function for data loading
 loadData :: String -- ^ Cluster or URL to use as source
          -> IO (Result ClusterData)
-loadData master = readData master >>= return . parseData
+loadData = fmap parseData . readData
diff --git a/htools/Ganeti/HTools/Text.hs b/htools/Ganeti/HTools/Text.hs
index 964fd8a38..052fd33f2 100644
--- a/htools/Ganeti/HTools/Text.hs
+++ b/htools/Ganeti/HTools/Text.hs
@@ -188,4 +188,4 @@ parseData fdata = do
 -- | Top level function for data loading
 loadData :: String -- ^ Path to the text file
          -> IO (Result ClusterData)
-loadData afile = readData afile >>= return . parseData
+loadData = fmap parseData . readData
-- 
GitLab