On 02/12/2013 06:11 PM, Patrick Hurst wrote:
On Tue, Feb 12, 2013 at 10:03 AM, Adam Chlipala <ad...@csail.mit.edu <mailto:ad...@csail.mit.edu>> wrote:

    On 02/12/2013 12:48 AM, Patrick Hurst wrote:

        fun formResultToRows  (fl : folder assns) (result : $(mapU
        assignmentData assns)) : list assignmentVariant =
            @foldUR [assignmentData] [fn cols => list (variant (mapU
        unit cols))]
            (fn [nam :: Name] [rest ::_] [[nam] ~ rest] res acc =>
                make [nam] () :: List.mp Variant.weaken acc
            )
            [] fl result

    In particular, I bet [Variant.fold] from the meta library is just
    what you need here.

    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. :])


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.

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.

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.)

The [R] suffix means that the fold is over a (value-level) _R_ecord.
_______________________________________________
Ur mailing list
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to