[Ur] This is an expression but not a pattern

Artyom Shalkhakov artyom.shalkhakov at gmail.com
Sat Apr 9 10:16:43 EDT 2016


Hello Yves,

2016-04-09 19:18 GMT+06:00 Yves Cloutier <yves.cloutier at gmail.com>:
> Hello, regarding forms, what is the signature of r for the record that is
> passed to the handler function?
>
> I am trying to do something like:
>
> <submit value="Add Employer" action={Employers.add}/>
>
> I have defined a module below for the purpose, but compiling gives an error
> pointing at the following line:
>
>       val getList = queryL1 (SELECT * FROM tblEmployers)
>
>
> for which I have defined the signature to be:
>
>      val getList:  transaction (list {Id : int, Description : string, From :
> string, To : string})
>
> Following the example in Fig 1 of Ur/Web: A Simple Model for Programming the
> Web.
>
> I do think this is fine, but that maybe the error is for the next function:
>
>       val add:      unit -> transaction unit
>

The type of parameter should not be a [unit]. Try something like:

> val add : {Description:string,From:string} -> transaction unit

And the form should mention the names [Description] and [From]. Like
in the example:

> <textbox{#Description}/>

> Who's purpose is to be the handler for a form submit. After looking at the
> manual, basis.ur and top.ur, I am still not certain which type r (the record
> created by submitting a form).
>
> If someone could give me a tip that would great.  Below is the full code for
> my module.
>
> structure Employers: sig
>
>   (* Function that returns a list of employers from table tblEmployers *)
>   val getList:  transaction (list {Id : int, Description : string, From :
> string, To : string})
>
>   (* A handler for "Add Employer" form button *)
>   val add:      unit -> transaction unit
>
>   (* Function that takes a employer ID and removes it from table
> tblEmployers *)
>   val remove:   int -> transaction unit
> end = struct
>
>   (* A sequence to generate unique employer ID *)
>   sequence uidEmployer
>
>   (* A table of employers *)
>   table tblEmployers : {Id: int, Description: string, From: time, To: time}
>
>   val getList = queryL1 (SELECT * FROM tblEmployers)
>
>   fun add r = val nextId  = nextval uidEmployer
>               dml (INSERT INTO tblEmployers (Id, Description, From, To)
>                    VALUES ({[nextId]}, {[r.Description]}, {[r.From]},
> {[r.To]}))
>
>   fun remove uidEmployer = dml (DELETE * FROM tblEmployers WHERE t.Id =
> {[uidEmployer.Id]})
> end
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>



-- 
Cheers,
Artyom Shalkhakov



More information about the Ur mailing list