This type safety is just the foundation of the Ur/Web methodology. It is also possible to use metaprogramming to build significant application pieces by analysis of type structure. The Ur/Web compiler also produces very efficient object code that does not use garbage collection. The implementation of all this is open source. SQL syntax templates embedded in the language facilitate the handling of tables. Although the syntax is based on Standard ML the language includes concepts from Haskell with additional type manipulation. Ajax call/response is serialized through a monad called transaction and its marshalling and decoding is encapsulated in the rpc function. The browser client side includes functional reactive programming facilities using the type and a signal monad.
Example program
This is a demo program showing client, server and database code with Ajax communication, from the web demos, with extra comments to outline each of the components: Interface file with.urs extension: val main : unit -> transaction page
ro <- oneOrNoRows ; case ro of None => return None | Some r => return fun check ls = case ls of Nil => return | Cons => ao <- rpc ; alert ; check ls' fun main = idAdd <- source ""; aAdd <- source ""; idDel <- source "";
return
Project file, must contain an optional directive list followed by a listing of project modules: # hash prefixed line comments rewrite url Module1/main # set root URL to Module1/main function exe myexename database dbname=test # database attrib. and parameters sql noisy.sql $/list # stdlib modules prefixed with "$/" module2 # if used by module1 it must precede it module1 # main module
server side, page retrieving functions with no side effects are accessible through a URL as /ModulePath/functionName, they should have type
.
To export a page which may cause side effects, accessible only via HTTP POST, include one argument of the page handler of type
Basis.postBody.Compile: urweb module1 # looks for module1.urp Execute as a web server : ./module1.exe -p 8081 # -h : RTS options help''
: mystruc k v = if k1 < kmin then error setKey: illegal k1 else case my of Node r => Node | _ => error setKey: not a Node
corresponding signature implicit; : con mystruc :: Type -> Type -> Type val setKey : k ::: Type -> v ::: Type -> ord k -> string -> k -> mystruc k v -> mystruc k v
Record fields ellipsis
case my of Node => doWhatever k | _ =>....
Error "Substitution in constructor is blocked by a too-deep unification variable"
This error happens with types of arity > 0 in nested case or let clauses and disappears by type annotating the variables in the nested clauses.