Re: [Ur] Ur/Web -> JavaScript objects

2019-10-16 Thread Adam Chlipala

On 10/16/19 4:17 AM, Artyom Shalkhakov wrote:

I think this is what you are looking for:

https://github.com/vizziv/UrLib/blob/master/UrLib/record.urs#L36
https://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23

It would be very nice if we as a community were to come up with a 
"batteries included" library for Ur/Web.
The equivalent code I maintain is in UPO 
, though I 
didn't bother to define this particular operator, since, as Mark showed 
us, it is so directly expressed with built-in operators.
___
Ur mailing list
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur


Re: [Ur] Ur/Web -> JavaScript objects

2019-10-16 Thread Mark Clements
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://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23

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 
mailto:mark.cleme...@ki.se>>:
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
> Ur@impredicative.com
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Furdata=02%7C01%7Cmark.clements%40ki.se%7Cc261896e2002436d168d08d74c3223c8%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637061651008402618sdata=d0C41U6idMCbn%2F%2B8hSEdEj7fTNvzU2tdf8Jx4olkTT8%3Dreserved=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.


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.
___
Ur mailing list
Ur@impredicative.com

Re: [Ur] Ur/Web -> JavaScript objects

2019-10-16 Thread Artyom Shalkhakov
Hello Mark,

I think this is what you are looking for:

https://github.com/vizziv/UrLib/blob/master/UrLib/record.urs#L36
https://github.com/vizziv/UrLib/blob/master/UrLib/record.ur#L23

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 :

> 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
> > Ur@impredicative.com
> >
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Furdata=02%7C01%7Cmark.clements%40ki.se%7Cc261896e2002436d168d08d74c3223c8%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637061651008402618sdata=d0C41U6idMCbn%2F%2B8hSEdEj7fTNvzU2tdf8Jx4olkTT8%3Dreserved=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.
> ___
> Ur mailing list
> Ur@impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>


-- 
Cheers,
Artyom Shalkhakov
___
Ur mailing list
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur


Re: [Ur] Ur/Web -> JavaScript objects

2019-10-16 Thread Mark Clements
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
> Ur@impredicative.com
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.impredicative.com%2Fcgi-bin%2Fmailman%2Flistinfo%2Furdata=02%7C01%7Cmark.clements%40ki.se%7Cc261896e2002436d168d08d74c3223c8%7Cbff7eef1cf4b4f32be3da1dda043c05d%7C0%7C0%7C637061651008402618sdata=d0C41U6idMCbn%2F%2B8hSEdEj7fTNvzU2tdf8Jx4olkTT8%3Dreserved=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.


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.
___
Ur mailing list
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur


Re: [Ur] Ur/Web -> JavaScript objects

2019-10-08 Thread Adam Chlipala

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
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur