columnv2 => moins de lignes, utilisation de list comprehension

master
karchnu 2016-01-08 04:29:12 +01:00
parent c20d0b6e0b
commit a92640a487
1 changed files with 19 additions and 0 deletions

19
haskell/columnv2.hs Normal file
View File

@ -0,0 +1,19 @@
import Data.List as L
formatLine :: [String] -> [String]
formatLine x = map (\e -> e ++ [' ' | _ <- [length e..nb]]) x
where nb = maximum $ map length x
formatLines :: [[String]] -> [[String]]
formatLines x = map formatLine x
completeMatrix :: [[String]] -> [[String]]
completeMatrix m = map (\e -> e ++ [""| _ <- [length e..nb]]) m
where nb = maximum $ map length m
column :: [[String]] -> [[String]]
column x = L.transpose $ formatLines $ L.transpose $ completeMatrix x
main = do
content <- getContents
putStr $ unlines $ map unwords $ column $ map words $ lines content