<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 12, 2013 at 10:03 AM, Adam Chlipala <span dir="ltr"><<a href="mailto:adamc@csail.mit.edu" target="_blank">adamc@csail.mit.edu</a>></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 02/12/2013 12:48 AM, Patrick Hurst wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
My code so far is<br>
<br></div>
[...]<div class="im"><br>
<br>
fun formResultToRows (fl : folder assns) (result : $(mapU assignmentData assns)) : list assignmentVariant =<br>
@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>
<br></div>
[...]<div class="im"><br>
<br>
/home/phurst/code/assignments/<u></u>assignments.ur:34:27: (to 34:41) Can't resolve type class instance<br>
Class constraint: Top.folder[[Type]] (map (fn _ :: Unit => {}) rest)<br>
<br>
so I assume I need to explicitly pass in a folder somewhere (possibly to Variant.weaken?), but I'm not sure how. Any advice?<br>
</div></blockquote>
<br>
I hope that file locations from the error message are indeed pointing to the [Variant.weaken] call; that's where I expect the problem is.<br>
<br>
The compiler only infers [folder]s for types with known field names, which isn't the case here, so a [folder] needs to be passed explicitly. Generally you preface an identifier with [@] to turn off automatic insertion of arguments for [folder]s and type class witnesses. You could use that method here to allow you to give an appropriate [folder], if you had one.<br>
<br>
However, I think it would be hard to come up with that [folder] (actually a sequence of [folder]s, one for each fold iteration). Instead, I think a more specialize fold operation is a better match.<br>
<br>
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>