[Ur] Default settings using a generic record update

Ziv Scully zivscully at gmail.com
Tue Oct 29 11:39:50 EDT 2019


One can capture subset constraints using a type class, as the following
module does:

https://github.com/vizziv/UrLib/blob/master/UrLib/subset.urs
https://github.com/vizziv/UrLib/blob/master/UrLib/subset.ur

(It relies on another module, Eq, from the same project.)

Ziv


On Tue, Oct 29, 2019 at 11:21 Mark Clements <mark.clements at ki.se> wrote:

> Adam: thank you for your prompt reply.
>
> To define defaultSettings properly, is there some way to constraint the
> type union (keep ++ change) to an existing type (e.g. {A:int, B:int})?
> The following also do not work:
>
> fun defaultSetting
>      [keep] [change] [keep ~ change]
>      (args : $change)
>      : $(keep ++ change) =
>      update {A=1, B=1} args
>
> (* or *)
>
> fun defaultSetting
>          [keep] [change] [keep ~ change]
>          (args : $change)
>      : $(keep ++ change) =
>      {A=1,B=1} --- change ++ args
>
> -- Mark
>
> On 29/10/19 12:52 am, Adam Chlipala wrote:
> > On 10/28/19 3:27 PM, Mark Clements wrote:
> >> fun defaultSetting args =
> >>       update {A=1, B=1} args
> >>
> >> val _ = defaultSetting {A=2} (* {A=2, B=1} *)
> >> val _ = defaultSetting {B=2} (* {A=1, B=2} *)
> > The problem is that polymorphism in Ur/Web is always declared
> > explicitly, not inferred as OCaml or Haskell.  You must add binders
> > for type variables for defaultSettings just as you did for update.
> > (This statement applies to definitions of functions, not uses, so the
> > two example calls above should work once you get defaultSettings
> > defined properly.)
>
>
>
> 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
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20191029/3b9a16b7/attachment-0001.html>


More information about the Ur mailing list