Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Ur (programming language)

From Wikipedia, the free encyclopedia
Ur, Ur/Web
Paradigmsfunctional,reactive
FamilyML,Haskell
Designed byAdam Chlipala
First appearedDecember 2014; 10 years ago (2014-12)[1]
Stable release
20200209 / February 9, 2020; 5 years ago (2020-02-09)
Typing disciplinestatic, row
Platformx86-64
OSPOSIX
LicenseMIT
Filename extensions.ur, .urs, .urp
Websiteimpredicative.com/ur
Influenced by
ML,Haskell[2]

Ur, also calledUr/Web, is amulti-paradigm,high-level,pure,strict,functionalprogramming language. It is adialect of the languageML, designed forweb development, created by Adam Chlipala at theMassachusetts Institute of Technology[3] that one program can emit code for aserver,web browser client, andSQL specific to a givendatabasebackend. The full implementation isfree and open-source software released under anMIT License.[2]

Ur has its start and roots in a superseded progenitor language namedLaconic/Web,[4] in 2006.[5]

Function

[edit]

Ur supports a powerful kind ofmetaprogramming based onrowdata types.[2]

Ur/Web is Ur plus a special standardlibrary and associated rules forparsing and optimizing. Ur/Web supports construction ofdynamic web pages and applications backed bySQL 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 ofcode injection attacks
  • Return invalidHTML
  • Contain dead intra-application links
  • Have mismatches betweenHTML 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 invalidSQL queries
  • Use impropermarshaling or unmarshaling in communication withSQL databases or betweenweb browsers andweb servers

Thistype 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]

TheUr/Web compiler also produces very efficient object code that does not usegarbage collection.[2]

SQL syntax templates embedded in the language facilitate the handling of tables.

Although the syntax is based onStandard ML the language includes concepts fromHaskell with added type manipulation.

Ajax call/response is serialized through amonad calledtransaction (corresponds to Haskell'sinput/output (IO)) and its marshalling and decoding is encapsulated in therpc function.

The browser client side includesfunctionalreactive programming facilities using the(source a) type and asignalmonad.

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

[6]

Example program

[edit]

This is a demo program showing client, server and database code withAjax communication, from the web demos,[7] 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:[8]

# 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 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 typeBasis.postBody.[9]

Compile:

urweb module1# looks for module1.urp

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

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

Libraries

[edit]

Special features and problems

[edit]
  • Record updating
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
  • Record fields ellipsis
casemyofNode{Key=k,...}=>doWhateverk|_=>....
  • Error "Substitution in constructor is blocked by a too-deep unification variable"[10]

This error happens with types ofarity> 0 in nestedcase orlet clauses and disappears by type annotating the variables in the nested clauses.

See also

[edit]
  • Opa, a language for combined frontend-backend development

References

[edit]
  1. ^UrWeb is out of beta
  2. ^abcdef"The Ur Programming Language Family". Impredicative.com/ur. Retrieved3 April 2016.
  3. ^Chlipala, Adam (January 2015)."Ur/Web: A Simple Model for Programming the Web". MIT / Association for Computing Machinery (ACM). Retrieved5 January 2015.
  4. ^Chlipala, Adam (2006)."The Laconic programming language family".SourceForge.
  5. ^Chlipala, Adam (2006)."Scrap Your Web Application Boilerplate, or Metaprogramming with Row Types".Adam.Chlipala.net.
  6. ^Hardesty, Larry (December 23, 2014)."Taking the grunt work out of Web development". Massachusetts Institute of Technology: MIT News. Retrieved29 December 2016.
  7. ^Ur language demo programs
  8. ^Chlipala, Adam (January 2015)."The Ur/Web Manual – Project files".GitHub. Retrieved8 January 2015.
  9. ^The Ur/Web Manual - The Structure of Web Applications
  10. ^Unexpected type error: "Substitution in constructor is blocked by a too-deep unification variable"

External links

[edit]
ML programming
Software
Implementations,
dialects
Caml
Standard ML
Dependent ML
Programming tools
Theorem provers,
proof assistants
Community
Designers
  • Lennart Augustsson (Lazy ML)
  • Damien Doligez (OCaml)
  • Gérard Huet (Caml)
  • Xavier Leroy (Caml, OCaml)
  • Robin Milner (ML)
  • Don Sannella (Extended ML)
  • Don Syme (F#)
  • Haskell programming
    Software
    Implementations
    (features)
    Dialects
    Electronic
    design
    Libraries
    Package managers
    Windowing systems
    Web frameworks
    Book
    Community
    Eponym
    Retrieved from "https://en.wikipedia.org/w/index.php?title=Ur_(programming_language)&oldid=1261860904"
    Categories:
    Hidden categories:

    [8]ページ先頭

    ©2009-2025 Movatter.jp