Content deleted Content added
m →See also: fix |
Jerryobject (talk | contribs) Template:Infobox programming language, WP:REFerence WP:CITation parameters: adds, fills, reorders, respaces, underscores > spaces, update-standardizes, corrects, conform to master templates. WP:LINKs: update-standardizes, needless WP:PIPEs > WP:NOPIPEs, WP:ANCHOR add. Nonlead-word nonproper noun MOS:CAPS > WP:LOWERCASE sentence case. MOS:FIRSTABBReviations clarify, define before WP:ABBRs in parentheses. Adds: WP:NAVBOX, WP:CATEGORY. |
||
Line 3:
{{Infobox programming language
| name = Elm
| logo =
| logo size = 120px
| paradigm = [[Functional programming|Functional]]▼
| logo caption = The Elm tangram
| released = {{Start date and age|2012|3|30}}<ref name="initialrelease">{{cite web|url=https://www.reddit.com/r/haskell/comments/rkyoa/my_thesis_is_finally_complete_elm_concurrent_frp/|last1=Czaplicki|first1=Evan|title=My Thesis is Finally Complete! "Elm: Concurrent FRP for functional GUIs"|website=[[Reddit]]|date=30 March 2012}}</ref>▼
| latest release version = 0.19.1▼
| latest release date = {{Start date and age|2019|10|21}}<ref>{{Cite web|url=https://github.com/elm/compiler/releases|title = Releases · elm/Compiler| website=[[GitHub]] }}</ref>▼
| influenced_by = [[Haskell (programming language)|Haskell]], [[Standard ML]], [[OCaml]], [[F Sharp (programming language)|F#]]▼
| influenced = [[Redux (JavaScript library)|Redux]],<ref>{{cite web|url=https://redux.js.org/introduction/prior-art|title=Prior Art - Redux|website=redux.js.org}}</ref> [[Rust (programming language)|Rust]],<ref>{{Cite web |title=Uniqueness Types |url=https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html |access-date=2016-10-08 |website= Rust Blog |quote="Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach."}}</ref> [[Vue.js#Official libraries|Vue]],<ref>{{cite web|url=https://vuejs.org/v2/guide/comparison.html#Scale|title=Comparison with Other Frameworks — Vue.js}}</ref> Roc,<ref>{{Cite web |title=roc/roc-for-elm-programmers.md at main · roc-lang/roc |url=https://github.com/roc-lang/roc/blob/main/roc-for-elm-programmers.md |access-date=2024-02-17 |website=[[GitHub]] |language=en |quote="Roc is a direct descendant of the Elm programming language. The two languages are similar, but not the same!"}}</ref> Derw,<ref>{{cite web| title= Why Derw: an Elm-like language that compiles to TypeScript? |url= https://derw.substack.com/p/why-derw-an-elm-like-language-that}}</ref> Gren<ref>{{cite web| title= Gren 0.1.0 is released |url= https://gren-lang.org/news/220530_first_release/}}</ref>▼
| typing = [[static typing|Static]], [[strong typing|Strong]], [[type inference|Inferred]]▼
| designer = Evan Czaplicki
▲| released = {{Start date and age|2012|
▲| latest release version = 0.19.1
▲| latest release date = {{Start date and age|2019|10|21}}<ref>{{Cite web |url=https://github.com/elm/compiler/releases |title
▲| typing = [[
| platform = [[x86-64]]
| operating system = [[macOS]], [[Microsoft Windows|Windows]]
| license = [[Permissive license|Permissive]] ([[BSD license|Revised BSD]])<ref name=license>{{cite web |url=https://github.com/elm/compiler/blob/master/LICENSE |title=elm/compiler |website=GitHub|date=16 October 2021}}</ref>▼
| website = {{Official URL}}
▲|
▲| license = [[Permissive license|Permissive]] ([[BSD license|Revised BSD]])<ref name=license>{{cite web|url=https://github.com/elm/compiler/blob/master/LICENSE|title=elm/compiler|website=GitHub|date=16 October 2021}}</ref>
▲| influenced = [[Redux (JavaScript library)|Redux]],<ref>{{cite web |url=https://redux.js.org/introduction/prior-art |title=Prior Art - Redux |website=redux.js.org}}</ref> [[Rust (programming language)|Rust]],<ref>{{Cite web |title=Uniqueness Types |url=https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html |access-date=2016-10-08 |website= Rust Blog |quote=
▲| file_ext = .elm
}}
'''Elm''' is a [[Domain-specific language|___domain-specific]] [[programming language]] for [[Declarative programming|declaratively]] creating [[web browser]]-based [[graphical user interface]]s. Elm is [[purely functional programming|purely functional]], and is developed with emphasis on [[usability]], performance, and [[Robustness (computer science)|robustness]]. It advertises "no [[Runtime (program lifecycle phase)|runtime]] [[Exception handling|exceptions]] in practice",<ref>{{cite web |url=https://elm-lang.org/ |title=Elm home page}}</ref> made possible by the Elm compiler's [[Type system#Static type checking|static type checking]].
== History ==
Elm was initially designed by Evan Czaplicki as his thesis in 2012.<ref>{{cite web |url=https://elm-lang.org/assets/papers/concurrent-frp.pdf |title=Elm: Concurrent FRP for Functional GUIs}}</ref> The first release of Elm came with many examples and an online editor that made it easy to try out in a [[web browser]].<ref>{{cite web |url=https://elm-lang.org/try |title=Try Elm |website=elm-lang.org |access-date=2019-07-24|archive-url=https://web.archive.org/web/20170521144831/http://elm-lang.org/try|archive-date=2017-05-21 |url-status=dead}}</ref> Mr. Czaplicki joined [[Prezi]] in 2013 to work on Elm,<ref>{{cite web |url=https://elm-lang.org/news/elm-and-prezi |title=elm and prezi |website=elm-lang.org}}</ref> and in 2016 moved to [[NoRedInk]] as an Open Source Engineer, also starting the Elm Software Foundation.<ref>{{cite web |url=https://elm-lang.org/news/new-adventures-for-elm |title=new adventures for elm |website=elm-lang.org}}</ref>
The initial implementation of the Elm compiler
== Features ==
Elm has a small set of language constructs, including traditional if-expressions, let-expressions for storing local values, and case-expressions for [[pattern matching]].<ref name="syntax">{{cite web |url=http://elm-lang.org/learn/Syntax.elm |title=syntax |website=elm-lang.org |access-date=2013-05-31|archive-url=https://web.archive.org/web/20160313052210/http://elm-lang.org/learn/syntax.elm|archive-date=2016-03-13 |url-status=dead}}</ref> As a functional language, it supports [[anonymous function]]s, functions as arguments, and functions can return functions, the latter often by partial application of curried functions. Functions are called by value. Its semantics include immutable values, [[pure function|stateless functions]], and static typing with type inference. Elm programs render HTML through a virtual DOM, and may interoperate with other code by using "JavaScript as a service".
=== Immutability ===
All values in Elm are [[Immutable object|immutable]], meaning that a value cannot be modified after it is created. Elm uses [[persistent data structure]]s to implement its arrays, sets, and dictionaries in the standard library.<ref>{{cite web |url=https://package.elm-lang.org/packages/elm/core/latest/ |title=elm/core |website=package.elm-lang.org}}</ref>
=== Static types ===
Elm is statically typed. Type annotations are optional (due to type inference) but strongly encouraged. Annotations exist on the line above the definition (unlike C-family languages where types and names are interspersed). Elm uses a single colon to mean "has type".
Types include primitives like integers and strings, and basic data structures such as lists, tuples, and records. Functions have types written with arrows, for example <code>round : Float -> Int</code>. [[tagged union|Custom types]] allow the programmer to create custom types to represent data in a way that matches the problem ___domain.<ref>{{cite web
Types can refer to other types, for example a <code>List Int</code>. Types are always capitalized; lowercase names are type variables. For example, a <code>List a</code> is a list of values of unknown type. It is the type of the empty list and of the argument to <code>List.length</code>, which is agnostic to the list's elements. There are a few special types that programmers create to interact with the Elm runtime. For example, <code>Html Msg</code> represents a (virtual) DOM tree whose event handlers all produce messages of type <code>Msg</code>.
Line 39 ⟶ 43:
Rather than allow any value to be implicitly nullable (such as JavaScript's <code>undefined</code> or a [[null pointer]]), Elm's standard library defines a <code>Maybe a</code> type. Code that produces or handles an optional value does so explicitly using this type, and all other code is guaranteed a value of the claimed type is actually present.
Elm provides a limited number of built-in [[type class]]es: <code>number</code> which includes <code>Int</code> and <code>Float</code> to facilitate the use of numeric operators such as <code>(+)</code> or <code>(*)</code>, <code>comparable</code> which includes numbers, characters, strings, lists of comparable things, and tuples of comparable things to facilitate the use of comparison operators, and <code>appendable</code> which includes strings and lists to facilitate concatenation with <code>(++)</code>. Elm does not provide a mechanism to include custom types into these type classes or create new type classes (see
=== Module system ===
Line 45 ⟶ 49:
=== Interoperability with HTML, CSS, and JavaScript ===
Elm uses an abstraction called ports to communicate with [[JavaScript]].<ref>{{cite web |url=https://guide.elm-lang.org/interop/ |title=JavaScript interop |website=elm-lang.org}}</ref> It allows values to flow in and out of Elm programs, making it possible to communicate between Elm and JavaScript.
Elm has a library called elm/html that a programmer can use to write HTML and CSS within Elm.<ref>{{cite web |url=https://package.elm-lang.org/packages/elm/html/latest/ |title=elm/html |website=package.elm-lang.org}}</ref> It uses a virtual [[Document Object Model|DOM]] approach to make updates efficient.<ref>{{cite web |url=https://elm-lang.org/news/blazing-fast-html |title=Blazing Fast HTML |website=elm-lang.org}}</ref>
=== Backend ===
Elm does not officially support server-side development. The core development team does not consider it as their primary goal and prefers to focus development on the enhancement of front-end development experience. Nevertheless, there are several independent projects, which attempt to explore possibilities to use Elm for the back-end. The projects are mainly stuck on Elm version 0.18.0 since newer ones do not support "native" code and some other utilized features. There are two attempts to use Elm with BEAM (Erlang virtual machine). One of the projects executes Elm directly on the environment<ref>{{Cite web |url=https://github.com/hkgumbs/elm-beam |title = Kofigumbs/Elm-beam
== The Elm Architecture ==
The Elm Architecture is a [[software design pattern]] for building interactive web applications. Elm applications are naturally constructed in that way, but other projects may find the concept useful.
An Elm program is always split into three parts:
* Model - the state of the application
* View - a function that turns the model into HTML
Line 64 ⟶ 67:
Those are the core of the Elm Architecture.
For example, imagine an application that displays a number and a button that increments the number when pressed.<ref>{{Cite web |title=Buttons · An Introduction to Elm |url=https://guide.elm-lang.org/architecture/buttons.html |access-date=2020-10-15 |website=guide.elm-lang.org}}</ref> In this case, all we need to store is one number, so our model can be as simple as <code>type alias Model = Int</code>. The <code>view</code> function would be defined with the <code>Html</code> library and display the number and button. For the number to be updated, we need to be able to send a message to the <code>update</code> function, which is done through a custom type such as <code>type Msg = Increase</code>. The <code>Increase</code> value is attached to the button defined in the <code>view</code> function such that when the button is clicked by a user, <code>Increase</code> is passed on to the <code>update</code> function, which can update the model by increasing the number.
In the Elm Architecture, sending messages to <code>update</code> is the only way to change the state. In more sophisticated applications, messages may come from various sources: user interaction, initialization of the model, internal calls from <code>update</code>, subscriptions to external events (window resize, system clock, JavaScript interop...) and URL changes and requests.
==
Elm does not support [[Type class#Higher-kinded polymorphism|higher-kinded polymorphism]],<ref>{{cite web |title=Higher-Kinded types Not Expressible? #396 |url=https://github.com/elm-lang/elm-compiler/issues/396 |website=github.com/elm-lang/elm-compiler |access-date=6 March 2015}}</ref> which related languages [[
This means that, for example, Elm does not have a generic <code>map</code> function which works across multiple data structures such as <code>List</code> and <code>Set</code>. In Elm, such functions are typically invoked qualified by their module name, for example calling <code>List.map</code> and <code>Set.map</code>. In Haskell or PureScript, there would be only one function <code>map</code>. This is a known feature request that is on Mr. Czaplicki's rough roadmap since at least 2015.<ref>{{cite web |title=Higher-Kinded types Not Expressible #396 |url=https://github.com/elm/compiler/issues/396#issuecomment-128190898 |website=github.com/elm-lang/elm-compiler |access-date=19 November 2019}}</ref>
Another outcome is a large amount of [[boilerplate code]] in medium to large size projects as illustrated by the author of "Elm in Action" in their single page application example<ref>{{cite web |title=Main.elm |url=https://github.com/rtfeldman/elm-spa-example/blob/23dee34dd7a8c26229a03bc8e9f0e034f6222f13/src/Main.elm |website=github.com/rtfeldman/elm-spa-example |access-date=30 June 2020}}</ref> with almost identical fragments being repeated in update, view, subscriptions, route parsing and building functions.
== Example code ==
Line 165 ⟶ 168:
== External links ==
* {{Official website}}
* {{GitHub|elm|Elm}}
{{Haskell programming}}
{{Programming languages}}
Line 171 ⟶ 176:
[[Category:Domain-specific programming languages]]
[[Category:Functional languages]]
[[Category:Haskell programming language family]]
[[Category:Pattern matching programming languages]]
[[Category:Programming languages created in 2012]]
|