[Ur] feature request: forward url declarations

Sergey Mironov grrwlf at gmail.com
Sun Jul 13 05:43:36 EDT 2014


Hi. I'm trying to solve the old problem regarding application design:
pass a set of urls to the main-page template function. Consider the
following pattern (see code below). Every page of this application
should have a link to the very first 'greetings' page (see [s]
parameter of the [template] function). That's why we should declare
[main] before [static]. But from the other hand, [main] also uses
[Crud] which needs [static] to render it's internal pages. So we have
a declaration loop here.

IMHO, the easiest way to solve this loop is to allow user to obtain
function urls after their signatures are declared in *urs but before
their bodies are declared in *ur. It may work analogous to C function
pointers.

Other solution (less transparent in my eyes) may be to allow
[structure] definition in the middle of [fun .. and .. and] chain.

What do you think? May be there is a solution already?

Regards,
Sergey

--

type static = { Main : url, About : url, Title : string }

fun template (s:static) (mb:transaction xbody) : transaction page =
  b <- mb;
  return <xml><body>
      <h1><a href={s.Main}>Main page</a></h1>
      <hr/>
      {b}
      </body></xml>

(* statics has to refer to main by url *)
val statics : static = { Title = "Competitions", Main = url (main {}),
About = url (about {}) }

structure C = Crud.Make(
  struct
     val tab = compet

     val seq = competSeq

     val cols = {CName = Crud.string "Name", Hide = Crud.bool "Hide?"}

     (* I've modified Crud from the urweb/demo to take additional parameters *)
     val st = statics
  end)

(* Greeting page refers to Crud which uses statics, so we have a loop *)
fun main {} : transaction page = template statics (
   return <xml>
   Welcome to the application.
   <a link={C.main {}}> Start </a>
   </xml>
   )

fun about {} : transaction page = return <xml><body>About page</body></xml>



More information about the Ur mailing list