简化Haskell中的丑陋功能

dev*_*ium 3 haskell functional-programming coding-style

我已经定义了这个功能 f1

f1 p = foldl (\x y -> x ++ y ++ "\t") "" (map (foldl (++) "") p)
Run Code Online (Sandbox Code Playgroud)

这需要

[["4","0","1"],["5","2","3"]]
Run Code Online (Sandbox Code Playgroud)

和产量

"401\t523\t"
Run Code Online (Sandbox Code Playgroud)

但它是一个丑陋的功能,因为它可以获得.我确信有一种更简单的方法来实现相同的功能.有人能给我一些线索吗?

Car*_*arl 9

功能构成是你的朋友.所以是从Data.List插入的

f1 = intercalate "\t" . map concat
Run Code Online (Sandbox Code Playgroud)

编辑:哎呀,误读你的输出.你想要"\ t"在所有这些结尾,而不仅仅是它们之间.在那种情况下,它更接近

f1 = concat . map ((++ "\t") . concat)
Run Code Online (Sandbox Code Playgroud)

  • 吞噬极乐世界,我的第二个函数不使用Data.List中的任何东西 (2认同)