<div dir="ltr">On Sat, Sep 17, 2011 at 22:11, Anton Tayanovskyy <span dir="ltr">&lt;<a href="mailto:anton.tayanovskyy@gmail.com">anton.tayanovskyy@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
By the way, can Haskell have a type that admits regular expression and<br>
only those? I mostly do ML these days, so trying to write up a regex<br>
types in Haskell I was unpleasantly surprised to discover that there<br>
are all sorts of exotic terms inhabiting it, which I did not have to<br>
worry about in ML. Besides `undefined` you can have for terms that try<br>
to define a grammar with nested parentheses. Using regex-applicative<br>
syntax:<br>
<br>
expr = ... &lt;|&gt; pure (\ _ x _ -&gt; x) &lt;*&gt; sym &quot;(&quot; &lt;*&gt; expr &lt;*&gt; sym &quot;)&quot;<br></blockquote><div><br></div><div>The general case for this is solving the Halting Problem, so neither Haskell nor any other language can do it.  You can disallow infinite values by encoding the length into the type, but (a) in Haskell this is painful and (b) runtime values now require runtime types, which you can accommodate but at the price of reintroducing the problems you are trying to prevent.  (Dependently typed languages work better for this, but I suspect the result is rather more draconian than you intend.)</div>
</div><div><br></div>-- <br>brandon s allbery                                      <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a><br>wandering unix systems administrator (available)     (412) 475-9364 vm/sms<br>
<br>
</div>