<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>The easiest solution I found is to add this directive to
      test.urp: monoInline 10</p>
    <p>Short rationale: the compiler uses conservative program analysis
      to find opportunities to get rid of first-class functions.  Uses
      of the [transaction] monad are compiled internally into
      first-class functions, so we need to get rid of all their
      first-classness, as the compiler for server-side code currently
      doesn't support functions at runtime.  Extra inlining can help
      reveal more structure to the program analysis, and it did so in
      this case.<br>
    </p>
    <div class="moz-cite-prefix">On 02/27/2017 11:22 AM, Artyom
      Shalkhakov wrote:<br>
    </div>
    <blockquote
cite="mid:CAKO6=qgPvCGqxyTo2TAJXHH6LobSLS1G=h3OiN14Db-i+knRfw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hello all,
        <div><br>
        </div>
        <div>So I hit a road-block, the code:</div>
        <div><br>
        </div>
        > fun groups (): transaction page =<br>
        >  m <- return ((Tregex.match'<br>
        >    (concat (literal "a") (capture [#X] (literal "b")))
        "ab")
        <div>>    : option {Whole:counted_substring,
          Groups:{X:counted_substring}});<br>
          >  case m of<br>
          >    None => return <xml>Failed:
          mismatch!</xml><br>
          >  | Some {Whole = whole, Groups = {X = {Start=s,Len=l}}}
          => return <xml>Success? Whole match: {[whole.Start]}
          + {[whole.Len]}, group is {[s]} + {[l]}</xml></div>
        <div><br>
        </div>
        <div>Gives this error:</div>
        <div><br>
        </div>
        <div>
          <div>> .../test.ur:137:17: (to 139:7) Anonymous function
            remains at code generation</div>
          <div>> Function:</div>
          <div>> (fn _ : {} =></div>
          <div>>   (case UNBOUND_1 of</div>
          <div>>     None => write("Failed: mismatch!") |</div>
          <div>>      Some {Whole = whole, Groups = {X = {Start = s,
            Len = l}}} =></div>
          <div>>       (write("Success? Whole match: ");</div>
          <div>>        (FFI(Basis.htmlifyInt_w(whole.Start));</div>
          <div>>         (write(" + ");</div>
          <div>>          (FFI(Basis.htmlifyInt_w(whole.Len));</div>
          <div>>           (write(", group is ");</div>
          <div>>            (FFI(Basis.htmlifyInt_w(s));</div>
          <div>>             (write(" + ");
            FFI(Basis.htmlifyInt_w(l)))))))))))</div>
        </div>
        <div><br>
        </div>
        <div>To reproduce, you'll have to build urweb-regex (I've put
          some directions into README in my branch) and then do [cd
          tests && make all]</div>
        <div><br>
        </div>
        <div>What can be done to avoid this issue? I tried to put type
          annotations, didn't work.</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">2017-02-25 9:30 GMT+06:00 Artyom
          Shalkhakov <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:artyom.shalkhakov@gmail.com" target="_blank">artyom.shalkhakov@gmail.com</a>></span>:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
            <span class=""><br>
              2017-02-23 21:55 GMT+06:00, Artyom Shalkhakov <<a
                moz-do-not-send="true"
                href="mailto:artyom.shalkhakov@gmail.com">artyom.shalkhakov@gmail.com</a>>:<br>
              > Hello Benjamin, Ziv,<br>
              ><br>
              > I wrote a very rough approximation to the idea that
              Ziv proposed, here's<br>
              > the code (currently, it does not do much):<br>
              ><br>
              > <a moz-do-not-send="true"
                href="https://github.com/ashalkhakov/urweb-regex/tree/typed-regex"
                rel="noreferrer" target="_blank">https://github.com/<wbr>ashalkhakov/urweb-regex/tree/<wbr>typed-regex</a><br>
              ><br>
              > At first I was thinking that it would be better to
              introduce named groups,<br>
              > but now I'm wondering how to handle positional
              groups, instead?<br>
              ><br>
              > Tangentially, I also noticed that JS does not handle
              capture groups mixed<br>
              > with repetition, e.g.<br>
              ><br>
              > 'xabxabxab'.match(/(xab){3}/) // or with /(xab)*/<br>
              ><br>
              > gives: ["xabxabxab", "xab"] (would it be worth it to
              try to rule out cases<br>
              > like this statically? probably not?)<br>
              ><br>
              <br>
            </span>I guess I figured it out. The idea is to keep track
            of index for every<br>
            group as well as the total count of groups in a regular
            expression.<br>
            Then, when constructing a capture:<br>
            <br>
            > capture [#Name] E<br>
            <br>
            the group indexes in E get incremented by 1, a new group is
            added:<br>
            {Name=0}, and the total count of groups is increased by 1.<br>
            <br>
            Similarly, when concatenating two expressions in<br>
            <br>
            > concat E1 E2<br>
            <br>
            the group indexes in E2 will all get incremented by N, where
            N is the<br>
            count of groups of E1.<br>
            <br>
            I think it should work.<br>
            <div class="HOEnZb">
              <div class="h5"><br>
                ><br>
                > 2017-02-21 21:21 GMT+06:00 Benjamin Barenblat <<a
                  moz-do-not-send="true" href="mailto:bbaren@mit.edu">bbaren@mit.edu</a>>:<br>
                ><br>
                >> On Mon, Feb 20, 2017 at 10:27 PM, Artyom
                Shalkhakov<br>
                >> <<a moz-do-not-send="true"
                  href="mailto:artyom.shalkhakov@gmail.com">artyom.shalkhakov@gmail.com</a>>
                wrote:<br>
                >> > Thank you for the pointer. I guess
                creating a new package that depends<br>
                >> > on<br>
                >> > urweb-regex is the way to go.<br>
                >><br>
                >> I’m also happy to merge changes to urweb-regex.
                I think a richly-typed<br>
                >> API like the one you’re looking for would be
                quite valuable in the<br>
                >> regex library.<br>
                >><br>
                >> ______________________________<wbr>_________________<br>
                >> Ur mailing list<br>
                >> <a moz-do-not-send="true"
                  href="mailto:Ur@impredicative.com">Ur@impredicative.com</a><br>
                >> <a moz-do-not-send="true"
                  href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur"
                  rel="noreferrer" target="_blank">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
                >><br>
                ><br>
                ><br>
                ><br>
                > --<br>
                > Cheers,<br>
                > Artyom Shalkhakov<br>
                ><br>
                <br>
                <br>
              </div>
            </div>
            <span class="HOEnZb"><font color="#888888">--<br>
                Cheers,<br>
                Artyom Shalkhakov<br>
              </font></span></blockquote>
        </div>
        <br>
        <br clear="all">
        <div><br>
        </div>
        -- <br>
        <div class="gmail_signature" data-smartmail="gmail_signature">Cheers,<br>
          Artyom Shalkhakov<br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Ur mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Ur@impredicative.com">Ur@impredicative.com</a>
<a class="moz-txt-link-freetext" href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur">http://www.impredicative.com/cgi-bin/mailman/listinfo/ur</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>