Elm (linguaggio di programmazione): differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Risolvo disambigua Haskell in Haskell (linguaggio) tramite popup
Finita traduzione
Riga 47:
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 [http://package.elm-lang.org/packages/ Elm Public Library].
 
=== InteroperabilityInteroperabilità withcon HTML, CSS, ande JavaScript ===
 
Elm usesusa anun'astrazione abstractionchiamata called"porte" portsper tocomunicare communicate withcon [[JavaScript]]. <ref>[http://elm-lang.org/learn/Ports.elm Ports]</ref> ItConsente allowsai valuesvalori todi flowfluire indentro ande outfuori ofda programmi Elm programs, making it possiblerendendo topossibile communicatecomunicare betweenfra Elm ande JavaScript.
 
Elm hasha auna librarylibreria calledchiamata "elm-html", thatche ai programmerprogrammatori canpossono useusare toper writespecificare codice HTML ande CSS withindall'interno di Elm. <ref>[http://package.elm-lang.org/packages/evancz/elm-html/latest/ elm-html documentation]</ref> ItUsa usesun aapproccio al [[virtual DOM virtuale]] approachper torendere makeefficienti updatesgli efficientaggiornamenti. <ref>[http://elm-lang.org/blog/Blazing-Fast-Html.elm Blazing Fast Html]</ref>
 
== LimitationsLimitazioni ==
Unlike [[Haskell (programming language)|Haskell]], Elm has no support for [[Kind (type theory)|higher-kinded types]], and thus cannot provide generic abstractions for many common operations.<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|accessdate=6 March 2015}}</ref> For example, there is no generic <code>map</code>, <code>apply</code>, <code>fold</code>, or <code>filter</code> function. Instead, such names are used prefixed by their module, such as <code>List.map</code> and <code>Dict.map</code>.
 
UnlikeDiversamente [[Haskellda (programming language)|Haskell]], Elm hasnon nosupporta supporti fortipi [[Kinddi (typelivello theory)|higher-kinded types]]superiore, ande thusquindi cannotnon providepuò genericfornire abstractionsastrazioni forgeneriche manyper commonmolte operationsoperazioni comuni. <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|accessdate=6 March 2015}}</ref> ForPer exampleesempio, therenon isci nosono genericfunzioni generiche <code>map</code>, <code>apply</code>, <code>fold</code>, or <code>filter</code> function. InsteadInvece, suchtali nomi si usano prefissi dal namesnome aredel usedmodulo prefixedin bycui theirsono moduledefiniti, suchcome asper <code>List.map</code> ande <code>Dict.map</code>.
== Tools ==
 
* Online editor at [http://elm-lang.org/try elm-lang.org/try] for easy experimentation
== Strumenti ==
* [https://github.com/elm-lang/elm-platform Elm Platform] for installing the core tools locally
 
* [http://debug.elm-lang.org/ Time-Traveling Debugger]
* Editor online [http://elm-lang.org/Learn.elmtry Learning resources] and [http://elm-lang.org/Examples.elmtry] examples]per facili esperimenti
* [https://github.com/elm-lang/elm-platform ElmPiattaforma PlatformElm] forper installare installinglocalmente thegli corestrumenti toolsdi locallybase
* [http://package.elm-lang.org/packages/elm-lang/core/latest/ Core Libraries] and [http://package.elm-lang.org/packages/ Community Libraries]
* [http://debug.elm-lang.org/ Time-Traveling Debugger che viaggia nel tempo]
* [http://elm-lang.org/Learn.elm Risorse di apprendimento] e [http://elm-lang.org/Examples.elm esempi]
* [http://package.elm-lang.org/packages/elm-lang/core/latest/ CoreLibrerie Librariesdi base] ande [http://package.elm-lang.org/packages/ Communitylibrerie della Librariescomunità]
 
== Codice di esempio ==
 
== Example code ==
<source lang="elm">
-- Questo è un commento su una sola riga
-- This is a single line comment
 
{- Questo è un commento su più righe.
{- This is a multi-line comment.
ItPuò canestendersi spansu multiplemolte linesrighe.
-}
 
{- I commenti su più righe possono essere {- annidati -} -}
{- It is possible to {- nest -} multi-line comments -}
 
-- HereQui wedefiniamo defineun avalore value namedchiamato ''greetingsaluti''. The typeIl istipo inferredviene asinferito aessere String.
saluti =
greeting =
"Hello World!"
 
-- È meglio aggiungere annotazioni di tipo alle dichiarazioni di primo livello.
-- It is best to add type annotations to top-level declarations.
hellociao : String
hellociao =
"Hi thereEhilà."
 
-- Le funzioni si dichiarano allo stesso modo, con gli argomenti che seguono il nome della funzione.
-- Functions are declared the same way, with arguments following the function name.
addaggiungi x y =
x + y
 
-- Ancora, è meglio aggiungere le annotazioni di tipo.
-- Again, it is best to add type annotations.
hypotenuseipotenusa : Float -> Float -> Float
hypotenuseipotenusa a b =
sqrt (a^2 + b^2)
 
-- Le espressioni `if` si usano per fare diramazioni in base a valori
-- If-expressions are used to branch on values
absoluteValuevaloreAssoluto : Int -> Int
valoreAssoluto numero =
absoluteValue number =
if numbernumero < 0 then -numbernumero else numbernumero
 
-- I record si usano per tenere valori in campi aventi un nome
-- Records are used to hold values with named fields
booklibro : { titletitolo:String, authorautore:String, pagespagine:Int }
booklibro =
{ titletitolo = "Steppenwolf"
, authorautore = "Hesse"
, pagespagine = 237
}
 
-- WePossiamo cancreare createtipi entirelycompletamente newnuovi typesusando withla theparola-chiave `type` keyword.
-- Il seguente valore rappresenta un albero binario.
-- The following value represents a binary tree.
type TreeAlbero a
= EmptyVuoto
| NodeNodo a (TreeAlbero a) (TreeAlbero a)
 
-- È possibile ispezionare questi tipi usando espressioni `case`.
-- It is possible to inspect these types with case-expressions.
depthprofondita : TreeAlbero a -> Int
profondita albero =
depth tree =
case treealbero of
EmptyVuoto -> 0
NodeNodo valuevalore leftsinistra rightdestra ->
1 + max (depthprofondita leftsinistra) (depthprofondita rightdestra)
</source>