<p dir="ltr">If I understood properly,</p>
<p dir="ltr">Have you considered breaking the input into some sort of pattern mask then validating it?</p>
<p dir="ltr">map (length . group) "AAABB" === [3,2]. Then you can do the same thing grouping with the target [x, x, y] into [2, 1]. Then you can zip the lists and ensure the numbers are all smaller than the other respectively. Also, the lists themselves have the right lengths and order for their elements.</p>
<p dir="ltr">Examples of successful patterns:</p>
<p dir="ltr">[1,1]<br>
AAA,BB</p>
<p dir="ltr">[1, 2]<br>
AAA,B,B</p>
<p dir="ltr">[2,1]<br>
A,AA,BB<br>
AA,A,BB</p>
<p dir="ltr">[2,2]<br>
A,AA,B,B<br>
AA,A,B,B</p>
<p dir="ltr">Try with other examples I think this would work.</p>
<div class="gmail_quote">On Jan 24, 2016 4:57 PM, "Simon Jakobi" <<a href="mailto:simon.jakobi@googlemail.com">simon.jakobi@googlemail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Francesco,<div><br></div><div>Thanks for your response!<br><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">    if I understood your specification correctly, there would be multiple<br>
ways to parse the string "AAA":<br>
<br>
    - 3 'x' elements ("A", "A", "A")<br>
    - 2 'x' elements ("AA", "A")<br>
    - 2 'x' elements again (first one shorter) ("A", "AA")<br>
    - 1 'x' element ("AAA")<br></blockquote><div><br></div><div>There would be even more ways because 'y', too, can represent one or more 'A's.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Which of these four should we choose?Maybe "parse as many As as possible<br>
without consuming the A followed by a series of B"?</blockquote><div><br></div><div>I don't think that there could be a general rule.</div><div><br></div><div>For the string "AABB" and the sequence of symbols [x, y, y] there would be two possible parses:</div><div><br></div><div>[x: "AA", y: "B", y: "B"]</div><div>or</div><div>[x: "A", y: "A", y: "BB"].</div><div><br></div><div>I only care whether there are any valid parses.</div><div><br></div><div>I've just tried to solve the problem with regular expressions (using pcre-light) and didn't come across the same problem. Is this due to attoparsec not being able to "backtrack" (not sure if this is the right term)? Is backtracking something that parsers generally are incapable of?</div><div><br></div><div>Cheers,</div><div>Simon</div></div></div></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div>