Ur (programming language)

Last updated
The Ur Programming Language Family
Paradigms functional, reactive
Family ML
Designed by Adam Chlipala
First appearedDecember 2014 [1]
Stable release
20200209 release / February 9, 2020;17 months ago (2020-02-09)
Platform POSIX
License open source
Filename extensions .ur, .urs, .urp
Website impredicative.com/ur
Influenced by
Haskell, ML [2]

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 [3] 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. [2]

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: [2]

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]

The implementation of all this is open source. [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 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 .

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."

[4]

Example program

This is a demo program showing client, server and database code with Ajax communication, from the web demos, [5] with extra comments to outline each of the components:

Interface file (ML-like signature) with .urs extension:

(* the environment monad is called transaction, corresponds to Haskell's IO monad *)valmain:unit->transactionpage

Implementation file (.ur extension):

datatypelistt=Nil|Consoft*listttablet:{Id:int,A:string}PRIMARYKEYId(* server side database access, called through AJAX XmlHttpRequest                    encapsulated as ''rpc'' function (remote procedure call) *)funaddids=(* sql dml template with {[expression]} *)dml(INSERTINTOt(Id,A)VALUES({[id]},{[s]}))fundelid=dml(DELETEFROMtWHEREt.Id={[id]})funlookupid=(* haskell style monadic code *)ro<-oneOrNoRows(SELECTt.AFROMtWHEREt.Id={[id]});caseroofNone=>returnNone(* return is the ''monad'' lifting function *)|Somer=>return(Somer.T.A)(* ''check'' called by client side onClick event handler,               so it will be compiled to JavaScript as page embedded client script *)funcheckls=caselsofNil=>return()|Cons(id,ls')=>ao<-rpc(lookupid);(* Ajax call to server side *)alert(caseaoofNone=>"Nada"|Somea=>a);checkls'funmain()=idAdd<-source"";aAdd<-source"";idDel<-source"";(* generates web page with JavaScript inclusions *)return<xml><body><buttonvalue="Check values of 1, 2, and 3"onclick={fn_=>letvalmylist=1::2::3::[]incheckmylistend}/><br/><br/><buttonvalue="Add"onclick={fn_=>id<-getidAdd;a<-getaAdd;rpc(add(readErrorid)a)(* Ajax call to server side *)}/><ctextboxsource={idAdd}/><ctextboxsource={aAdd}/><br/><br/><buttonvalue="Delete"onclick={fn_=>id<-getidDel;rpc(del(readErrorid))(* Ajax call to server side *)}/><ctextboxsource={idDel}/></body></xml>

Project file (.urp extension), must contain an optional directive list followed by a listing of project modules: [6]

# 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

Compile:

urweb module1   # looks for module1.urp

Execute as a web server (other modes are CGI, FastCGI, ...):

./module1.exe -p 8081   # -h : RTS options help

Libraries

Special features and problems

datatypemystruckv=Empty|Nodeof{Key:k,Value:v}funsetKey[k][v](* type polymorphism *)(_:ordk)(* implicit instance of class ord *)(callerErrNote:string)(k1:k)(my:mystruckv):mystruckv=ifk1<kminthenerror<xml>setKey:illegalk1{[callerErrNote]}</xml>elsecasemyofNoder=>Node(r--#Key++{Key=k1})|_=>error<xml>setKey:notaNode{[callerErrNote]}</xml>

corresponding signature (kind annotations (:::) implicit; (::) explicit):

conmystruc::Type->Type->Type(* two param. type constructor *)valsetKey:k:::Type->v:::Type->ordk->string->k->mystruckv->mystruckv
casemyofNode{Key=k,...}=>doWhateverk|_=>....

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.

See also

Related Research Articles

XML-RPC is a remote procedure call (RPC) protocol which uses XML to encode its calls and HTTP as a transport mechanism.

Web application Application that uses a web browser as a client

A web application is application software that runs on a web server, unlike computer-based software programs that are run locally on the operating system (OS) of the device. Web applications are accessed by the user through a web browser with an active network connection. These applications are programmed using a client–server modeled structure—the user ("client") is provided services through an off-site server that is hosted by a third-party. Examples of commonly-used web applications include: web-mail, online retail sales, online banking, and online auctions.

eXist-db is an open source software project for NoSQL databases built on XML technology. It is classified as both a NoSQL document-oriented database system and a native XML database. Unlike most relational database management systems (RDBMS) and NoSQL databases, eXist-db provides XQuery and XSLT as its query and application programming languages.

A database trigger is procedural code that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database. For example, when a new record is added to the employees table, new records should also be created in the tables of the taxes, vacations and salaries. Triggers can also be used to log historical data, for example to keep track of employees' previous salaries.

XML Interface for Network Services (XINS) is an open-source technology for definition and implementation of internet applications, which enforces a specification-oriented approach.

Web template system System in web publishing that lets web designers and developers work with web templates to automatically generate custom web pages

A web template system in web publishing lets web designers and developers work with web templates to automatically generate custom web pages, such as the results from a search. This reuses static web page elements while defining dynamic elements based on web request parameters. Web templates support static content, providing basic structure and appearance. Developers can implement templates from content management systems, web application frameworks, and HTML editors.

Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which may run either on the same computer or on another computer across a network. Microsoft markets at least a dozen different editions of Microsoft SQL Server, aimed at different audiences and for workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users.

ItsNat Natural AJAX, is an open-source Java component-based Ajax framework.

Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such as developing web forms from scratch, although a web developer may build a form from scratch if required.

A single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of a web browser loading entire new pages. The goal is faster transitions that make the website feel more like a native app.

The WSO2 Mashup Server is an open-source mashup platform that hosts JavaScript based mashups. It is based on Apache Axis2 and other open source projects, and provides JavaScript authors the ability to consume, compose and emit web services, feeds, scraped web pages, email, and instant messages. The source code is freely available under the open source Apache License. It provides a runtime platform for developing and deploying mashups. It can be downloaded and deployed locally or within an organization.

SOAPjr is a protocol specification for exchanging structured information in the implementation of web services in computer networks. It is a hybrid of SOAP and JSON-RPC.

XQuery is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats. The language is developed by the XML Query working group of the W3C. The work is closely coordinated with the development of XSLT by the XSL Working Group; the two groups share responsibility for XPath, which is a subset of XQuery.

Jspx-bay

jspx-bay, commonly referred to as jspx, is a free open source pure Java web RAD framework. Jspx should not be confused with other technologies using the same name like Oracle Application Framework and XML JSP.

Redis Open-source in-memory key–value database

Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices. The project was developed and maintained by Salvatore Sanfilippo. Since 2015, he led a project core team sponsored by Redis Labs. Salvatore Sanfilllippo left Redis as the maintainer in 2020. It is open-source software released under a BSD 3-clause license.

In computing, Open Data Protocol (OData) is an open protocol that allows the creation and consumption of queryable and interoperable REST APIs in a simple and standard way. Microsoft initiated OData in 2007. Versions 1.0, 2.0, and 3.0 are released under the Microsoft Open Specification Promise. Version 4.0 was standardized at OASIS, with a release in March 2014. In April 2015 OASIS submitted OData v4 and OData JSON Format v4 to ISO/IEC JTC 1 for approval as an international standard. In December 2016, ISO/IEC published OData 4.0 Core as ISO/IEC 20802-1:2016 and the OData JSON Format as ISO/IEC 20802-2:2016.

Opa (programming language)

Opa is an open-source programming language for developing scalable web applications.

Wakanda is a JavaScript platform to develop and run web or mobile apps.

PRADO (framework)

PRADO is an open source, object-oriented, event-driven, component-based PHP web framework. PRADO's name is an acronym derived from "PHP Rapid Application Development Object-oriented".

Yesod is a free and open-source web framework based on Haskell for productive development of type-safe, REST model based, high performance web applications, developed by Michael Snoyman et al.

References

  1. UrWeb is out of beta
  2. 1 2 3 4 5 6 "The Ur Programming Language Family". impredicative.com/ur. Retrieved 3 April 2016.
  3. Chlipala, Adam (January 2015). "Ur/Web: A Simple Model for Programming the Web". MIT / Association for Computing Machinery (ACM). Retrieved 5 January 2015.
  4. "Taking the grunt work out of Web development". mit.edu. December 23, 2014. Retrieved 29 December 2016.
  5. Ur language demo programs
  6. Chlipala, Adam (January 2015). "The Ur/Web Manual – Project files". https://enn.github.io/urweb-doc . Retrieved 8 January 2015.External link in |publisher= (help)
  7. The Ur/Web Manual - The Structure of Web Applications
  8. Unexpected type error: "Substitution in constructor is blocked by a too-deep unification variable"