<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
On 02/12/2013 06:11 PM, Patrick Hurst wrote:<br>
<blockquote
 cite="mid:CAGG20Np1Qh0+bOF6LXFjyFdWaqgd7+Nn8WyOhtJqZA4817FWxw@mail.gmail.com"
 type="cite">
  <div dir="ltr">
  <div class="gmail_extra">On Tue, Feb 12, 2013 at 10:03 AM, Adam
Chlipala <span dir="ltr"><<a moz-do-not-send="true"
 href="mailto:adamc@csail.mit.edu" target="_blank">adamc@csail.mit.edu</a>></span>
wrote:<br>
  <div class="gmail_quote">
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div class="im">On 02/12/2013 12:48 AM, Patrick Hurst wrote:<br>
    </div>
    <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">fun
formResultToRows  (fl : folder assns) (result : $(mapU assignmentData
assns)) : list assignmentVariant =<br>
      <div class="im">    @foldUR [assignmentData] [fn cols => list
(variant (mapU unit cols))]<br>
    (fn [nam :: Name] [rest ::_] [[nam] ~ rest] res acc =><br>
        make [nam] () :: List.mp Variant.weaken acc<br>
    )<br>
    [] fl result<br>
      </div>
    </blockquote>
In particular, I bet [Variant.fold] from the meta library is just what
you need here.<br>
    <br>
Also, if you are building a list of rows to insert into the database,
it will probably work better to instead execute one SQL INSERT per fold
iteration, so that no intermediate list needs to be materialized.
 Something like [Variant.app] would be appropriate for such a pattern.
 (Actually, it seems I only implemented a fancier version
[Variant.appR] so far, but I bet you could implement the natural
[Variant.app] and submit a patch with it. :])<br>
  </blockquote>
  <div style=""><br>
  </div>
  <div style="">I'm not sure how [Variant.fold] helps me out here,
since the thing I'm folding over with the [@foldUR] isn't a variant.
I'm fine with inserting something directly into the database inside the
fold as opposed to creating the list and then iterating over it, but
again I'm not sure how to use [Variant.app]  (what would that be? I'm
not sure what the R suffix means exactly) to implement it since I'm not
folding over a variant.</div>
  <div style=""><br>
  </div>
  <div style="">Do you mean I want to use [Variant.app] or
[Variant.fold] inside the [@foldUR]? If so, I'm not sure how to do so
by directly inserting inside the fold, since the type doesn't guarantee
me [nam] is in the relevant variant as far as I can tell, so I can't
insert it.</div>
  </div>
  </div>
  </div>
</blockquote>
<br>
I'm suggesting using [Variant.appR] instead of [foldUR], rather than
within the function passed to [foldUR].  (I just noticed the parameter
[result] that seems not to influence the result above, but probably is
meant to influence the result in the real code, so it seems that
actually [Variant.appR] is exactly what you need.)<br>
<br>
The [R] suffix means that the fold is over a (value-level) _R_ecord.<br>
</body>
</html>