[Haskell-beginners] Re: Iterating through a list of char...

Stephen Tetley stephen.tetley at gmail.com
Thu Apr 29 14:01:14 EDT 2010


Hello all

Correcting myself - in this case foldl is adequate - but it isn't
pleasant as the list is produced in the wrong order:

replaceCharAfterA_foldl' :: String -> String
replaceCharAfterA_foldl' xs = reverse $ snd $ foldl' f ('Z',[]) xs
  where
    f ('A',cca) b = (b,'*':cca)
    f (_,cca)   b = (b,b:cca)


demo2 = replaceCharAfterA_foldl' "abcABC"

> demo2
"abcA*C"

Best wishes

Stephen


More information about the Beginners mailing list