Ur_(programming_language)
Ur also called Ur/Web is a functional programming language designed for web development, created by Adam Chlipala at the Massachusetts Institute of Technology[3] that one program can emit code for a server, web browser client, and SQL specific to a given database backend. The full implementation is free and open-source software released under an MIT License.[2]
Ur supports a powerful kind of metaprogramming based on row types.[2]
Ur/Web is Ur plus a special standard library and associated rules for parsing and optimizing. Ur/Web supports construction of dynamic web pages and 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. They do not crash during particular page generations, and may not:[2]
- Suffer from any kinds of code injection attacks
- Return invalid HTML
- Contain dead intra-application links
- Have mismatches between HTML forms and the fields expected by their handlers
- Include client-side code that makes incorrect assumptions about the "Ajax"-style services that the remote web server provides
- Attempt invalid SQL queries
- Use improper marshaling or unmarshaling in communication with SQL databases or between web browsers and web servers
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.[2]
The Ur/Web compiler also produces very efficient object code that does not use garbage collection.[2]
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 added type manipulation.
Ajax call/response is serialized through a monad called transaction (corresponds to Haskell's input/output (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.
Ur/Web not only makes web applications easier to write, it also makes them more secure.
"Let's say you want to have a calendar widget on your web page, and you're going to use a library that provides the calendar widget, and on the same page there's also an advertisement box that's based on code that's provided by the ad network," Chlipala said.
"What you don't want is for the ad network to be able to change how the calendar works or the author of the calendar code to be able to interfere with delivering the ads."