You seem to have the right idea: you can indeed implement your own library
of "rpc forms". Try filling in this signature (that is, .urs file):

con rpcForm : {Type} -> Type

val create : fields ::: {Type} -> $fields -> transaction (rpcForm fields)

val textbox :
    others ::: {Type} -> nm :: Name -> [[nm] ~ others] =>
    rpcForm ([nm = string] ++ others) -> xbody

val submit :
    fields ::: {Type} -> result ::: Type ->
    rpcForm fields -> ($fields -> transaction result) -> transaction result

Here's an example usage:

val handle : {Name : string, FavColor : string} -> transaction unit =
    (* something with rpc... *)

val formExample : transaction page =
    fm <- create {Nm = "", FavColor = ""};
    return <xml>
      Your name: {textbox [Nm] fm}<br/>
      Your favorite color: {textbox [FavColor] fm}<br/>
      <button onclick={fn _ => submit fm handle}>Submit</button>
    </xml>

And here's a start to the implementation (that is, .ur file):

con rpcForm fields =
    $(map (fn t => {Source : source t, Default : t}) fields)

Once you have this working, you probably want to implement analogues of
textbox for other types. To be clear, I just came up with this off the top
of my head, so you will probably have to change some things.

Good luck!
Ziv

On Sun, Feb 11, 2018 at 7:24 PM, Aistis Raulinaitis <sheganin...@gmail.com>
wrote:

> Well I'm hoping to be able find some kind of happy middle between spurious
> reloads and verbosity of form definition.
>
> I'm fine with implementing a few abstractions myself, I'm just not sure
> what the correct direction is.
>
> Your widget system based on ML modules and functors is very interesting
> I'm just wondering how it would be possible to achieve what I'm attempting
> to do with as little friction as possible.
>
> On Feb 11, 2018 16:16, "Adam Chlipala" <ad...@csail.mit.edu> wrote:
>
>> Maybe just stop worrying about it, so that you might find that problems
>> don't arise in practice? >:)
>>
>> On 02/11/2018 07:13 PM, Aistis Raulinaitis wrote:
>>
>> Any pointers to get me started on the right path when it comes to a more
>> effective usage of source based forms?
>>
>> On Feb 11, 2018 16:09, "Adam Chlipala" <ad...@csail.mit.edu> wrote:
>>
>>> I'm not sure what to suggest.  No, there is no existing feature like
>>> what you suggest.  I have found it quite pleasant to work with sources and
>>> widgets connected to them.
>>>
>>> On 02/11/2018 05:03 PM, Aistis Raulinaitis wrote:
>>>
>>> The way that a form will pack all of its contents into a stuct is a
>>> clear advantage over the source based route. It requires defining possibly
>>> many sources and wiring them all into the right slots, having to call "get"
>>> on each one of them in the onclick handler and then wire all the gotten
>>> values into the handler.
>>>
>>>
>>
>> _______________________________________________
>> Ur mailing list
>> Ur@impredicative.com
>> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>>
>>
> _______________________________________________
> Ur mailing list
> Ur@impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
>
_______________________________________________
Ur mailing list
Ur@impredicative.com
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to