Simplifying an ugly function in Haskell

I defined a function f1

f1 p = foldl (\x y -> x ++ y ++ "\t") "" (map (foldl (++) "") p)

which will accept

[["4","0","1"],["5","2","3"]]

and get

"401\t523\t"

but the function is as ugly as it can be. I am sure there is an easier way to implement the same function. Can someone give me some idea about this?

+3
source share
2 answers

The composition of the function is your friend. So intercalates, from Data.List

f1 = intercalate "\t" . map concat

Edit: screaming, reading your output incorrectly. You want "\ t" at the end of all of them, not just between them. In this case, he is closer to

f1 = concat . map ((++ "\t") . concat)
+9
source

- (, ), , Haskell . , Data.List.unwords - , .

, :

http://hackage.haskell.org/packages/archive/base/4.3.0.0/doc/html/Data-List.html

unwords , , "". , . , ( ) .

+3

Source: https://habr.com/ru/post/1778201/


All Articles