I am a beginner, and write implementation of hangman in haskell.
Necessary to show guessed characters in ‘*‘-like string, currently I use that code:
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
If word was “shadow” and progress like “******”, char = ‘s’ function return “s****”.
How can I rewrite that function? I see that its not clean solution.
Solution (by @luqui):
proceed char = zipWith combine where
combine x y
| x == char = char
| otherwise = y
(“word” and “progress” arguments transfers to zipWith becose haskell’s eta-reduction)
You are right to think of
zip, you just seem to have done some extra work. See if you can write a suitable helper functioncombine: