Artyom: Very nice -- thank you.

Record.set is more general than my specification below, where the former also 
allows for the update to include new fields, but may require an explicit return 
type. For my specification, one could use:

fun updater
        [keep] [change] [keep ~ change]
        (xs : $(keep ++ change)) (ys : $change)
    : $(keep ++ change) =
    xs --- change ++ ys

which does not need an explicit return type and is simpler than using folders. 
Now that I see the code, it looks obvious...

+1 for a "batteries included" Ur/Web library.

Kindly, Mark.

On 16/10/19 10:17 am, Artyom Shalkhakov wrote:
Hello Mark,

I think this is what you are looking for:

https://github.com/vizziv/UrLib/blob/master/UrLib/record.urs#L36<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fvizziv%2FUrLib%2Fblob%2Fmaster%2FUrLib%2Frecord.urs%23L36&data=02%7C01%7Cmark.clements%40ki.se%7C91dafa24e5074ebd131708d752116f18%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637068107169183247&sdata=xFxmA5IBzthwVABlLnSs9%2Fx%2BJ5m9oOFa%2FmDbvoq%2BSe4%3D&reserved=0>
https://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fvizziv%2FUrLib%2Fblob%2Fmaster%2FUrLib%2Frecord.ur%23L23&data=02%7C01%7Cmark.clements%40ki.se%7C91dafa24e5074ebd131708d752116f18%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637068107169193243&sdata=dE0Q5%2B8%2FYmT7xIK0mp%2BafJgMRrGGYUbCBiUGQra%2Bc%2Bc%3D&reserved=0>

It would be very nice if we as a community were to come up with a "batteries 
included" library for Ur/Web.

ср, 16 окт. 2019 г. в 10:55, Mark Clements 
<[email protected]<mailto:[email protected]>>:
Adam: that is very cool -- thank you.

All: as a noob question, I can update a record using:
{A=1,B=2,C=3} --- [A=_,B=_] ++ {A=2,B=1}
or
{A=1,B=2,C=3} -- #A -- #B ++ {A=2,B=1}
==
{A=2, B=1, C=3}

How can I write a general record update function (assuming all fields in
the update record are in the base record), such that
let
   val base = {A=1,B=2,C=3}
   val update = {A=2,B=1}
in
   updater base update
end
==
{A=2, B=1, C=3}

I got as far as:

fun updater [tbase ::: {Type}] [tupdate ::: {Type}]
            (fl : folder tupdate) (base : $tbase) (update : $tupdate) :
$tbase =
     @foldR (* ?? *)
      (fn [nm ::_] [t ::_] [rest ::_] [[nm] ~ rest] t acc =>
          acc -- nm ++ {nm = t})
      base fl update

Any guidance would be appreciated.

Kindly, Mark.

On 8/10/19 10:57 pm, Adam Chlipala wrote:
> On 10/6/19 5:45 PM, Mark Clements wrote:
>> In defining an FFI to a JavaScript library such as Chart.js, config
>> options may be defined in terms of (nested) JavaScript objects with a
>> range of potential keys/fields. Analogous to the xml tags, is there
>> any way to define a record type in Ur/Web that potentially includes a
>> subset of fields?
>
> In my own FFI wrapping so far, I have just given fields [option] types
> when they are optional, dealing with writing in [None] values for
> unused fields manually.  I don't think it's so bad!
>
> Since I never miss an opportunity to show off metaprogramming in
> Ur/Web, here's a function you can use to cast a record to a wider type
> where all the new fields have [option] types.
>
> fun expand [original ::: {Type}] [additional ::: {Type}] [original ~
> additional]
>            (fl : folder additional) (r : $original)
>     : $(original ++ map option additional) =
>     r ++ @map0 [option] (fn [t ::_] => None) fl
>
> fun foo (x : {A : int, B : option string, C : float, D : option bool,
> E : string}) =
>     42
>
> val example = foo (expand {A = 3, C = 1.234, D = Some True, E = "hi"})
>
>
> _______________________________________________
> Ur mailing list
> [email protected]<mailto:[email protected]>
> 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<https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Fur&data=02%7C01%7Cmark.clements%40ki.se%7C91dafa24e5074ebd131708d752116f18%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637068107169193243&sdata=JgYYf2swlu7uSNiaN1LJhcgcDeiyFegaXEf9oLG%2BV1U%3D&reserved=0>
>



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<https://ki.se/medarbetare/integritetsskyddspolicy>.


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<https://ki.se/en/staff/data-protection-policy>.
_______________________________________________
Ur mailing list
[email protected]<mailto:[email protected]>
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur<https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Fur&data=02%7C01%7Cmark.clements%40ki.se%7C91dafa24e5074ebd131708d752116f18%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637068107169203236&sdata=27a8Fp8Wqj7Y%2FAGYlpYfkdMo0Lp2pqHNBP6ggGvrij8%3D&reserved=0>


--
Cheers,
Artyom Shalkhakov



_______________________________________________
Ur mailing list
[email protected]<mailto:[email protected]>
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%7C91dafa24e5074ebd131708d752116f18%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637068107169233226&amp;sdata=Fn6unesq2tBZ7dHBwncjTurXZRke%2BmyJKiTmYaak15Y%3D&amp;reserved=0


_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to