ArticleslgStudy

computer science

Ur (programming language)

Ur (programming language) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Ur (programming language) rather than just read about it. In short: Ur, also called Ur/Web, is a multi-paradigm, high-level, pure, strict, functional programming language. It is a dialect of the language ML, designed for web development, created by Adam Chlipala at the Massachusetts Institute of Technology that one program can emit code for a server, web browser client, and SQL specific to a given database backend.

Key takeaways

  • Ur (programming language) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Ur (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Ur (programming language) from memory before moving on to harder problems.

Reference excerpt

Ur, also called Ur/Web, is a multi-paradigm, high-level, pure, strict, functional programming language. It is a dialect of the language ML, designed for web development, created by Adam Chlipala at the Massachusetts Institute of Technology 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. Ur has its start and roots in a superseded progenitor language named Laconic/Web, in 2006.

Function Ur supports a powerful kind of metaprogramming based on row data types. 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:

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. The Ur/Web compiler also produces very efficient object code that does not use garbage collection. 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.

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 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 (http GET method) are accessible through a URL as /ModulePath/functionName; they should have type (unit -> transaction page). 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 (other modes are CGI, FastCGI, ...):

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

Libraries The predefined API The standard library Per feature tests Ur wiki - Libraries and FFI bindings

Special features and problems Record updating

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

Record fields ellipsis

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.

See also Opa, a language for combined frontend-backend development

References

External links Official website Ur/Web on GitHub Ur wiki Archived 2019-02-01 at the Wayback Machine

Worked examples

Example 1 — a first encounter with Ur (programming language)

Start with the simplest possible case. Write down what Ur (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Ur (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Ur (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Ur (programming language)

In research
Ur (programming language) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Ur (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Ur (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Functional languages, Haskell programming language family, High-level programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Ur (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Ur (programming language)” →

How to study Ur (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Ur (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Ur (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Ur (programming language) in simple terms?

Ur, also called Ur/Web, is a multi-paradigm, high-level, pure, strict, functional programming language. It is a dialect of the language ML, designed for web development, created by Adam Chlipala at the Massachusetts Institute of Technology that one program can emit code for a server, web browser cl…

Why does Ur (programming language) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Ur (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Ur (programming language).

Tags

  • Functional languages
  • Haskell programming language family
  • High-level programming languages
  • ML programming language family
  • Massachusetts Institute of Technology software
  • Programming languages created in 2014
  • Software using the MIT license

Keep exploring