0
我是初学者,在haskell中编写hangman的实现。 必要显示在“*‘般的字符串,目前我使用的代码猜字:使用清单
proceed char word progress = let zprog = zip progress [0..] in
foldl (\a x -> a ++ [fst x]) "" $ map (f char word) zprog where
f c w el =
if c == w !! (snd el) then
(c, snd el)
else
el
如果词是‘影子’等进步‘******’,字符=’ s'函数返回“s ****”。
我该如何重写该函数?我看到它不是干净的解决方案。 溶液(@luqui):
proceed char = zipWith combine where
combine x y
| x == char = char
| otherwise = y
( “字”, “进步” 的论点转移到zipWith becose Haskell的ETA还原)
该死的男人,太神奇了! –
为了获得更多乐趣,请尝试从该函数的源中删除所有出现的'word'和'progress' – luqui
哇,缩小(不知道名称),我读过它,谢谢。 –