Ur (programming language)


Ur also called Ur/Web is a Free and Open source functional programming language specific for web development, created by Adam Chlipala at the Massachusetts Institute of Technology that from a single program produces server code, browser client code and SQL code specific for the chosen database backend.
Ur supports a powerful kind of metaprogramming based on row types.
Ur/Web is Ur plus a special standard library and associated rules for parsing and optimization. Ur/Web supports construction of dynamic web applications backed by SQL databases. The signature of the standard library is such that well-typed Ur/Web programs "don't go wrong" in a very broad sense. Not only do they not crash during particular page generations, but they also may not:
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

Implementation file :

datatype list t = Nil | Cons of t * list t
table t :
PRIMARY KEY Id
fun add id s =

dml VALUES )
fun del id =
dml
fun lookup id =

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