[Ur] This is an expression but not a pattern

Yves Cloutier yves.cloutier at gmail.com
Sat Apr 9 09:18:13 EDT 2016


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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20160409/223b91d9/attachment.html>


More information about the Ur mailing list