【发布时间】:2017-05-09 08:16:49
【问题描述】:
我正在尝试在 Haskell 中打印一组单词和每个单词的长度。单词在 .txt 文件中,所以首先我必须将内容放入 Haskell,然后将它们拆分为单个单词,所以到目前为止我这样做了:
main =
do
textdat <- openFile "palindrom.txt" ReadMode
inhalt <- hGetContents textdat
winhalt <- return (words inhalt)
print winhalt
putStrLn "has the length "
print (length winhalt)
palindrom.txt 是我从中提取单词的 .txt 文件。使用 openFile 和 hGetContents,我将 .txt 的内容分配给“inhalt”。 “winhalt”是使用“words”功能将内容分成单词。 现在我得到这个结果:
"wordexample1""wordexample2""wordexample3"..."wordexample45"
has the length
45
(45是.txt文件的字数)
如何将单词序列拆分为单个单词,以便分别获取和打印每个单词的长度?
【问题讨论】: