Elm (linguaggio di programmazione)
Elm è un linguaggio di programmazione ___domain-specific per creare dichiarativamente interfacce-utente grafiche basate su browser web. Elm è puramente funzionale, ed è sviluppato dando priorità all'usabilità, alle prestazioni, e alla robustezza. Sostiene di evitare praticamente qualunque eccezione in fase di esecuzione "[2], grazie alle verifiche statiche del compilatore Elm.
| Elm linguaggio di programmazione | |
|---|---|
|  | |
| Autore | Evan Czaplicki | 
| Data di origine | 2012 | 
| Ultima versione | 0.18 | 
| Utilizzo | generazione pagine Web dinamiche | 
| Paradigmi | programmazione funzionale | 
| Tipizzazione | forte, statica, inferita | 
| Estensioni comuni | .elm | 
| Influenzato da | Haskell, Standard ML, OCaml, F# | 
| Implementazione di riferimento | |
| Lingua | Inglese | 
| Licenza | Permissiva (Revised BSD) [1] | 
| Sito web | [elm-lang.org elm-lang.org]. | 
Storia
Elm è stato progettato inizialmente da Evan Czaplicki come progetto di tesi nel 2012. [3] I primo rilascio di Elm era accompagnato da molti esempi e da un editor online che rendeva facile provare il linguaggio in un browser Web. [4] Evan Czaplicki joined Prezi in 2013 to work on Elm,[5] and in 2016 moved to NoRedInk as an Open Source Engineer, also starting the Elm Software Foundation.[6]
L'implementazione iniziale del compilatore Elm genera codice HTML, CSS, e JavaScript. [7] L'insieme di strumenti di base si è continuato a espandere, e adesso comprende un interprete interattivo, [8] un gestore di pacchetti, [9] un debugger che consente viaggi nel tempo, [10] e degli installatori per Mac e Windows.[11] Inoltre, Elm ha un ecosistema di librerie create dalla comunità di utenti. [12]
Caratteristiche
Elm ha un insieme piccolo ma espressivo di costrutti linguistici, tra cui espressioni `if`, espressioni `let`, espressioni `case`, funzioni anonime, e interpolazioni di lista. [13][14] Le caratteristiche chiave comprendono l'immutabilità, la tipizzazione statica, e l'interoperabilità con HTML, CSS, e JavaScript.
Immutabilità
Tutti i valori in Elm sono immutabili, cioè nessun valore può essere modificato dopo che è stato creato. Elm usa strutture dati persistenti per implementare le sua librerie Array, Dict, e Set. [15]
Tipizzazione statica
Elm è tipizzato staticamente. Ogni definizione in Elm può ricevere un'annotazione di tipo che descrive la forma esatta del valore. Tra i tipi ci sono:
- tipi primitivi come interi e stringhe
- strutture dati di base come liste, ennuple, e record estendibili
- tipi personalizzati, chiamati `unioni taggate` che consentono di costruire tipi interamente nuovi [16]
Elm supporta anche la completa inferenza di tipo, così che il compilatore possa verificare che un programma sia type-safe anche senza annotazioni di tipo.
Sistema di moduli
Elm ha un sistema di moduli che consente ai programmatori di suddividere il loro codice in parti più piccole, chiamate "moduli". I programmatori possono importare ed esportare simboli, rendendo possibile nascondere i dettagli implementativi che non sono necessari agli altri moduli. I moduli formano la base del sito Web della libreria dela comunità di Elm, la Elm Public Library.
Interoperability with HTML, CSS, and JavaScript
Elm uses an abstraction called ports to communicate with JavaScript.[17] 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.[18] It uses a virtual DOM approach to make updates efficient.[19]
Limitations
Unlike Haskell, Elm has no support for higher-kinded types, and thus cannot provide generic abstractions for many common operations.[20] For example, there is no generic map, apply, fold, or filter function. Instead, such names are used prefixed by their module, such as List.map and Dict.map.
Tools
- Online editor at elm-lang.org/try for easy experimentation
- Elm Platform for installing the core tools locally
- Time-Traveling Debugger
- Learning resources and examples
- Core Libraries and Community Libraries
Example code
-- This is a single line comment
{- This is a multi-line comment.
   It can span multiple lines.
-}
{- It is possible to {- nest -} multi-line comments -}
-- Here we define a value named ''greeting''. The type is inferred as a String.
greeting =
    "Hello World!"
 -- It is best to add type annotations to top-level declarations.
hello : String
hello =
    "Hi there."
-- Functions are declared the same way, with arguments following the function name.
add x y =
    x + y
-- Again, it is best to add type annotations.
hypotenuse : Float -> Float -> Float
hypotenuse a b =
    sqrt (a^2 + b^2)
-- If-expressions are used to branch on values
absoluteValue : Int -> Int
absoluteValue number =
    if number < 0 then -number else number
 -- Records are used to hold values with named fields
book : { title:String, author:String, pages:Int }
book =
    { title = "Steppenwolf"
    , author = "Hesse"
    , pages = 237 
    }
-- We can create entirely new types with the `type` keyword.
-- The following value represents a binary tree.
type Tree a
    = Empty
    | Node a (Tree a) (Tree a)
-- It is possible to inspect these types with case-expressions.
depth : Tree a -> Int
depth tree =
    case tree of
      Empty -> 0
      Node value left right ->
          1 + max (depth left) (depth right)
References
- ^ https://github.com/evancz/Elm/blob/master/LICENSE
- ^ Elm home page, su elm-lang.org.
- ^ Elm: Concurrent FRP for Functional GUIs
- ^ Elm's Online Editor
- ^ Elm joins Prezi
- ^ New Adventures for Elm
- ^ Elm compiler source code
- ^ Elm REPL announcement
- ^ Elm Package Manager announcement
- ^ Elm's Time-Traveling Debugger
- ^ Elm Platform
- ^ Elm Public Libraries
- ^ The Syntax of Elm
- ^ About Elm Elm features
- ^ Elm Standard Libraries
- ^ Model The Problem, su elm-lang.org. URL consultato il 4 May 2016.
- ^ Ports
- ^ elm-html documentation
- ^ Blazing Fast Html
- ^ Higher-Kinded types Not Expressible? #396, su github.com. URL consultato il 6 March 2015.