<div dir="ltr"><div>Hello Mark,</div><div><br></div><div>I think this is what you are looking for:<br></div><div><br></div><div><a href="https://github.com/vizziv/UrLib/blob/master/UrLib/record.urs#L36">https://github.com/vizziv/UrLib/blob/master/UrLib/record.urs#L36</a></div><div><a href="https://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23">https://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23</a></div><div><br></div><div>It would be very nice if we as a community were to come up with a "batteries included" library for Ur/Web.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">ср, 16 окт. 2019 г. в 10:55, Mark Clements <<a href="mailto:mark.clements@ki.se">mark.clements@ki.se</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Adam: that is very cool -- thank you.<br>
<br>
All: as a noob question, I can update a record using:<br>
{A=1,B=2,C=3} --- [A=_,B=_] ++ {A=2,B=1}<br>
or<br>
{A=1,B=2,C=3} -- #A -- #B ++ {A=2,B=1}<br>
==<br>
{A=2, B=1, C=3}<br>
<br>
How can I write a general record update function (assuming all fields in<br>
the update record are in the base record), such that<br>
let<br>
   val base = {A=1,B=2,C=3}<br>
   val update = {A=2,B=1}<br>
in<br>
   updater base update<br>
end<br>
==<br>
{A=2, B=1, C=3}<br>
<br>
I got as far as:<br>
<br>
fun updater [tbase ::: {Type}] [tupdate ::: {Type}]<br>
            (fl : folder tupdate) (base : $tbase) (update : $tupdate) :<br>
$tbase =<br>
     @foldR (* ?? *)<br>
      (fn [nm ::_] [t ::_] [rest ::_] [[nm] ~ rest] t acc =><br>
          acc -- nm ++ {nm = t})<br>
      base fl update<br>
<br>
Any guidance would be appreciated.<br>
<br>
Kindly, Mark.<br>
<br>
On 8/10/19 10:57 pm, Adam Chlipala wrote:<br>
> On 10/6/19 5:45 PM, Mark Clements wrote:<br>
>> In defining an FFI to a JavaScript library such as Chart.js, config<br>
>> options may be defined in terms of (nested) JavaScript objects with a<br>
>> range of potential keys/fields. Analogous to the xml tags, is there<br>
>> any way to define a record type in Ur/Web that potentially includes a<br>
>> subset of fields?<br>
><br>
> In my own FFI wrapping so far, I have just given fields [option] types<br>
> when they are optional, dealing with writing in [None] values for<br>
> unused fields manually.  I don't think it's so bad!<br>
><br>
> Since I never miss an opportunity to show off metaprogramming in<br>
> Ur/Web, here's a function you can use to cast a record to a wider type<br>
> where all the new fields have [option] types.<br>
><br>
> fun expand [original ::: {Type}] [additional ::: {Type}] [original ~<br>
> additional]<br>
>            (fl : folder additional) (r : $original)<br>
>     : $(original ++ map option additional) =<br>
>     r ++ @map0 [option] (fn [t ::_] => None) fl<br>
><br>
> fun foo (x : {A : int, B : option string, C : float, D : option bool,<br>
> E : string}) =<br>
>     42<br>
><br>
> val example = foo (expand {A = 3, C = 1.234, D = Some True, E = "hi"})<br>
><br>
><br>
> _______________________________________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
> <a href="https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Fur&amp;data=02%7C01%7Cmark.clements%40ki.se%7Cc261896e2002436d168d08d74c3223c8%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637061651008402618&amp;sdata=d0C41U6idMCbn%2F%2B8hSEdEj7fTNvzU2tdf8Jx4olkTT8%3D&amp;reserved=0" rel="noreferrer" target="_blank">https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Fur&amp;data=02%7C01%7Cmark.clements%40ki.se%7Cc261896e2002436d168d08d74c3223c8%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637061651008402618&amp;sdata=d0C41U6idMCbn%2F%2B8hSEdEj7fTNvzU2tdf8Jx4olkTT8%3D&amp;reserved=0</a><br>
><br>
<br>
<br>
<br>
När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<<a href="https://ki.se/medarbetare/integritetsskyddspolicy" rel="noreferrer" target="_blank">https://ki.se/medarbetare/integritetsskyddspolicy</a>>.<br>
<br>
<br>
Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<<a href="https://ki.se/en/staff/data-protection-policy" rel="noreferrer" target="_blank">https://ki.se/en/staff/data-protection-policy</a>>.<br>
_______________________________________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
<a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/cgi-bin/mailman/listinfo/ur</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Cheers,<br>Artyom Shalkhakov<br></div></div>