showLangToSloc :: OptVerbose -> LangToSloc -> String
showLangToSloc verbose = unlines . map display . sortBy compareSloc . M.toList
  where
    compareSloc :: (Language, [(FilePath, Int)]) -> (Language, [(FilePath, Int)]) -> Ordering
    compareSloc (lang1, fs1) (lang2, fs2) = sumSnds fs2 `compare` sumSnds fs1 <> lang1 `compare` lang2

    display :: (Language, [(FilePath, Int)]) -> String
    display (lang, fs) = unlines $
        show lang : lineCounts
      where
        lineCounts :: [String]
        lineCounts =
            if verbose
                then map (\(fp,n) -> "      " ++ show n ++ " " ++ fp) (sortBy (\a b -> snd b `compare` snd a) fs)
                else ["      " ++ show (sumSnds fs)]
showLangToSloc :: OptVerbose -> LangToSloc -> String
showLangToSloc verbose = unlines . map display . sortBy compareSloc . M.toList
  where
    compareSloc :: (Language, [(FilePath, Int)]) -> (Language, [(FilePath, Int)]) -> Ordering
    compareSloc (lang1, fs1) (lang2, fs2) = sumSnds fs2 `compare` sumSnds fs1 <> lang1 `compare` lang2

    display :: (Language, [(FilePath, Int)]) -> String
    display (lang, fs) = unlines $
        show lang : lineCounts
      where
        lineCounts :: [String]
        lineCounts =
            if verbose
                then map (\(fp,n) -> "      " ++ show n ++ " " ++ fp) (sortBy (\a b -> snd b `compare` snd a) fs)
                else ["      " ++ show (sumSnds fs)]
showLangToSloc verbose = unlines . map display . sortBy compareSloc . M.toList
  where
    compareSloc :: (Language, [(FilePath, Int)]) -> (Language, [(FilePath, Int)]) -> Ordering
    compareSloc (lang1, fs1) (lang2, fs2) = sumSnds fs2 `compare` sumSnds fs1 <> lang1 `compare` lang2

    display :: (Language, [(FilePath, Int)]) -> String
    display (lang, fs) = unlines $
        show lang : lineCounts
      where
        lineCounts :: [String]
        lineCounts =
            if verbose
                then map (\(fp,n) -> "      " ++ show n ++ " " ++ fp) (sortBy (\a b -> snd b `compare` snd a) fs)
                else ["      " ++ show (sumSnds fs)]