Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I might give you some ideas towards the working algorithm.</p> <p>First of all, you need to divide your input <code>String</code> into parts (<code>[String]</code>) according to your <code>find</code> strings. So this function is</p> <pre><code>divideIntoParts :: [String] -&gt; String -&gt; [String] </code></pre> <p>which works something like </p> <pre><code>divideIntoParts find "The House with Mouse is big" </code></pre> <p>gives </p> <pre><code>["The ", "Hou", "se with ", "Mouse", " is big"] </code></pre> <p>So it extracts the parts to replace from the string, but preserves the order of letters by keeping other parts in the same list. The naive implementation might look like this</p> <p><a href="https://gist.github.com/Shekeen/5523749" rel="nofollow">https://gist.github.com/Shekeen/5523749</a></p> <p>Next you'll need a function to scan through this list and replace the parts, which need to be replaced. The signature will be</p> <pre><code>replaceParts :: [String] -&gt; [String] -&gt; [String] -&gt; String </code></pre> <p>which works like</p> <pre><code>replaceParts find repl $ divideIntoParts find "The House with Mouse is big" </code></pre> <p>will be</p> <pre><code>"The Mouse with House is big" </code></pre> <p>So your full <code>replace</code> function will look like</p> <pre><code>replacePatterns :: [String] -&gt; [String] -&gt; String -&gt; String replacePatterns find repl = (replaceParts find repl) . (divideIntoParts find) </code></pre> <p>Also you really need to implement a faster substring search algorithm and consider replacing <code>find</code> and <code>repl</code> with one <code>Data.Map</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload