Designed by Adam Chlipala | Family ML First appeared December 2014 | |
Stable release 20160306 release / March 6, 2016; 12 months ago (2016-03-06) |
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.
Contents
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 (corresponds to Haskell's IO) and its marshalling and decoding is encapsulated in the rpc function.
The browser client side includes functional reactive programming facilities using the (source a)
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 (ML-like signature) with .urs extension:
Implementation file (.ur extension):
Project file (.urp extension), must contain an optional directive list followed by a listing of project modules:
# hash prefixed line commentsrewrite url Module1/main # set root URL to Module1/main functionexe myexenamedatabase dbname=test # database attrib. and parameterssql noisy.sql$/list # stdlib modules prefixed with "$/"module2 # if used by module1 it must precede itmodule1 # main moduleCompile:
urweb module1 # looks for module1.urpExecute as a web server (other modes are CGI, FastCGI, ...):
./module1.exe -p 8081 # -h : RTS options helpLibraries
Special features and problems
corresponding signature (kind annotations (:::) implicit; (::) explicit):
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.