[Haskell-cafe] Incrementation fails

Roel van Dijk vandijk.roel at gmail.com
Wed May 8 09:25:21 CEST 2013


Hi John,

Can you tell us what your function is supposed to do? It appears to be some
kind of search-and-replace for strings. What is the relationship between
'findStr', 'replaceStrList' and 'myText'?


2013/5/8 John <knowledge1202 at gmail.com>

> Hello All,
>
> I'm in a big trouble with incrementation of a counter in this code. It
> doesn't increment.
>
> Could you please tell me where the problem ist and how can I solve it?
>
> replaceBasedIdx    ::  String  ->  [String]  ->  String  ->  String
> replaceBasedIdx    findStr replaceStrList myText = replaceBasedIdxSub
> findStr replaceStrList myText 0
>
> replaceBasedIdxSub  ::  String  ->  [String]  ->  String  -> Int -> String
> replaceBasedIdxSub findStr replaceStrList myText counter = loop myText
>   where
>     loop [] = []
>     loop myText =
>       let (prefix, rest) = splitAt n myText
>       in
>         if findStr == prefix                                -- found an
> occurrence?
>         then (replaceStrList !! (counter+1)) ++ loop rest   -- yes: replace
> it
>
>         else head myText : loop (tail myText)               -- no: keep
> looking
>     n = length findStr
>
> Thank you very mutch!
>
> Greetings!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130508/79fa4c4f/attachment.htm>


More information about the Haskell-Cafe mailing list