<div dir="ltr">I don&#39;t think you can do much about &quot;fails to match the input string&quot; - indeed, that&#39;s often desired behavior...  and &quot;matches the wrong thing&quot; you can only catch with testing.<div>


<br></div><div>The simplest place template haskell could help with is when the expression isn&#39;t a valid expression in the first place, and will fail to compile.  If you&#39;re just validating, I don&#39;t think you can do better; in order to improve your confidence of correctness, your only option is testing against a set of positives and negatives.</div>


<div><br></div><div>If you&#39;re capturing, you might be able to do a little better, if you are able to get some of that info into the types (number of capture groups expected, for instance) - then, if your code expects to deal with a different number of captured pieces than your pattern represents, it can be caught at compile time.</div>
<div><br></div><div style>If you&#39;re capturing strings that you intend to convert to other types, and can decorate regexp components with the type they&#39;re going to capture (which can then be quickchecked - certainly a pattern should never match and then fail to read, &amp;c), and if you are able to propagate this info during composition, you might actually be able to catch a good chunk of errors.</div>
<div style><br></div><div style>Note that much of this works quite a bit different than most existing regexp library APIs, where you pass a bare string and captures wind up in some kind of list, which I expect is much of the reason no one&#39;s done it yet (so far as I&#39;m aware).</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 13, 2013 at 8:43 AM, Nicolas Trangez <span dir="ltr">&lt;<a href="mailto:nicolas@incubaid.com" target="_blank">nicolas@incubaid.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, 2013-02-13 at 08:39 -0800, David Thomas wrote:<br>
&gt; One way in which regexps are &quot;foreign to Haskell-think&quot; is that, if<br>
&gt; they<br>
&gt; break, they generally break at run-time.  This could be ameliorated<br>
&gt; with<br>
&gt; template haskell<br>
<br>
</div>Care to elaborate on the &quot;ameliorate using TH&quot; part? I figure regexes<br>
would be mostly used to parse some runtime-provided string, so how could<br>
compile-TH provide any help?<br>
<span class="HOEnZb"><font color="#888888"><br>
Nicolas<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>