[Ur] Using Variant.weaken in a foldUR
Patrick Hurst
phurst at mit.edu
Tue Feb 12 00:48:06 EST 2013
Right now I'm using Variant.weaken (where Variant is from the meta library
in http://hg.impredicative.com/meta ) in a record fold in hopes that I can
turn a value like
{ PS1 = ..., PS2 = ... }
into
[ { Id = make [#PS1] (), ... },
{ Id = make [#PS2] (), ... } ]
which I can then insert into a database. My code so far is
con assns :: {Unit} = [PS1, PS2, PS3]
type assignmentVariant = variant (mapU unit assns)
type assignmentData = { Title : string, Description : string }
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
(I can provide the full source file if necessary; right now I'm just
focusing on getting the IDs out.) The problem is that when I compile it I
get:
/home/phurst/code/assignments/assignments.ur:34:27: (to 34:41) Can't
resolve type class instance
Class constraint: Top.folder[[Type]] (map (fn _ :: Unit => {}) rest)
so I assume I need to explicitly pass in a folder somewhere (possibly to
Variant.weaken?), but I'm not sure how. Any advice?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20130212/6278adf2/attachment.html>
More information about the Ur
mailing list