Elm (programming language): Difference between revisions

Content deleted Content added
two notable influences of Elm
Tags: Mobile edit Mobile web edit
link tweaks
Line 9:
| latest release date = {{Start date and age|2019|10|21}}<ref>{{Cite web|url=https://github.com/elm/compiler/releases|title = Releases · elm/Compiler}}</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>, 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
Line 39:
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 [[Typetype class|type classes]]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 Limitations section).
 
=== Module system ===
Line 62:
* Update - a function that updates the model based on messages
 
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.
Line 69:
 
== Limitations ==
Elm does not support [[Type_classType class#Higher-kinded_polymorphismkinded 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 [[Haskell (programming language)|Haskell]] and [[PureScript]] offer, nor does Elm support the creation of [[Typetype class|type classes]]es.
 
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 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>
Line 110:
const : a -> b -> a
const k _ = k
 
 
-- Functions are also curried; here we've curried the multiplication