跳转到内容

Elm语言:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
第18行: 第18行:


==历史 ==
==历史 ==
Elm最初由Evan Czaplicki作为论文于2012年设计<ref>{{cite web|url=https://elm-lang.org/assets/papers/concurrent-frp.pdf|title=Elm: Concurrent FRP for Functional GUIs}}</ref>。Elm的首次发行带有很多例子和一个在线编辑器,使得易于在[[web浏览器]]中试验它<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}}</ref>。Evan在2013年加入[[Prezi]]从事Elm的工作<ref>{{cite web|url=https://elm-lang.org/news/elm-and-prezi|title=elm and prezi|website=elm-lang.org}}</ref>,并在2016年转移到{{en-link|NoRedInk}}作为开源工程师,并启动了Elm软件基金会<ref>{{cite web|url=https://elm-lang.org/news/new-adventures-for-elm|title=new adventures for elm|website=elm-lang.org}}</ref>。
Elm最初由Evan Czaplicki作为毕业论文于2012年设计<ref>{{cite web|url=https://elm-lang.org/assets/papers/concurrent-frp.pdf|title=Elm: Concurrent FRP for Functional GUIs}}</ref>。Elm的首次发行带有很多例子和一个在线编辑器,使得易于在[[web浏览器]]中试验它<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}}</ref>。Evan在2013年加入[[Prezi]]从事Elm的工作<ref>{{cite web|url=https://elm-lang.org/news/elm-and-prezi|title=elm and prezi|website=elm-lang.org}}</ref>,并在2016年转移到{{en-link|NoRedInk}}作为开源工程师,并启动了Elm软件基金会<ref>{{cite web|url=https://elm-lang.org/news/new-adventures-for-elm|title=new adventures for elm|website=elm-lang.org}}</ref>。


Elm编译器的最初实现执行目标为[[HTML]]、[[层叠样式表|CSS]]和[[JavaScript]]<ref>{{cite web|url=https://github.com/elm/compiler|title=elm/compiler|website=GitHub}}</ref>。核心工具集持续的扩展,现在包括了[[读取﹣求值﹣输出循环|REPL]]<ref>{{cite web|url=https://elm-lang.org/news/repl|title=repl|website=elm-lang.org}}</ref>、[[软件包管理系统|包管理器]]<ref>{{cite web|url=https://elm-lang.org/news/package-manager|title=package manager|website=elm-lang.org}}</ref>、时间旅行调试器<ref>{{cite web|url=https://elm-lang.org/news/time-travel-made-easy|title=Home|website=elm-lang.org}}</ref>和针对macOS及Windows的安装器<ref>{{cite web|url=https://guide.elm-lang.org/install.html|title=Install|website=guide.elm-lang.org}}</ref>。 Elm还有一个生态系统,包括社区创建的库<ref>[https://package.elm-lang.org/packages/ community created libraries]</ref>和Ellie<ref>[https://ellie-app.com Ellie]</ref>,它是一个高级在线编辑器,允许保存工作和包含社区库。
Elm编译器的最初实现执行目标为[[HTML]]、[[层叠样式表|CSS]]和[[JavaScript]]<ref>{{cite web|url=https://github.com/elm/compiler|title=elm/compiler|website=GitHub}}</ref>。核心工具集持续的扩展,现在包括了[[读取﹣求值﹣输出循环|REPL]]<ref>{{cite web|url=https://elm-lang.org/news/repl|title=repl|website=elm-lang.org}}</ref>、[[软件包管理系统|包管理器]]<ref>{{cite web|url=https://elm-lang.org/news/package-manager|title=package manager|website=elm-lang.org}}</ref>、时间旅行调试器<ref>{{cite web|url=https://elm-lang.org/news/time-travel-made-easy|title=Home|website=elm-lang.org}}</ref>和针对macOS及Windows的安装器<ref>{{cite web|url=https://guide.elm-lang.org/install.html|title=Install|website=guide.elm-lang.org}}</ref>。 Elm还有一个生态系统,包括社区创建的库<ref>[https://package.elm-lang.org/packages/ community created libraries]</ref>和Ellie<ref>[https://ellie-app.com Ellie]</ref>,它是一个高级在线编辑器,允许保存工作和包含社区库。

2021年2月28日 (日) 01:38的版本

Elm
The Elm tangram
编程范型函数式
設計者Evan Czaplicki
发行时间2012年3月30日,​12年前​(2012-03-30[1]
当前版本
  • 0.19.1 (2019年10月21日)
編輯維基數據鏈接
型態系統静态, 强类型, 类型推论
許可證宽松许可证 (修订的BSD)[2]
文件扩展名.elm
網站elm-lang.org 編輯維基數據鏈接
啟發語言
Haskell, Standard ML, OCaml, F#
影響語言
Redux,[3] Vuex[4]

Elm是一个领域特定编程语言,用于声明式的创建基于web浏览器图形用户界面。Elm是纯函数式的,开发它时强调了易用性、性能和健壮性。它宣传为“实际上没有运行时间异常[6],Elm编译器的静态类型检查使之成为可能。

历史

Elm最初由Evan Czaplicki作为毕业论文于2012年设计[7]。Elm的首次发行带有很多例子和一个在线编辑器,使得易于在web浏览器中试验它[8]。Evan在2013年加入Prezi从事Elm的工作[9],并在2016年转移到NoRedInk英语NoRedInk作为开源工程师,并启动了Elm软件基金会[10]

Elm编译器的最初实现执行目标为HTMLCSSJavaScript[11]。核心工具集持续的扩展,现在包括了REPL[12]包管理器[13]、时间旅行调试器[14]和针对macOS及Windows的安装器[15]。 Elm还有一个生态系统,包括社区创建的库[16]和Ellie[17],它是一个高级在线编辑器,允许保存工作和包含社区库。

特征

Elm有一个小集合的语言构造,包括传统的if表达式,let表达式用于局部状态,和case表达式用于模式匹配[18]。作为函数式语言,它缺省的支持匿名函数,函数作为实际参数,和部份应用。它的语义包括不可变的值,无状态函数,和具有类型推论的静态类型。Elm程序通过虚拟的DOM呈现HTML,还可以使用“JavaScript作为服务”来与其他代码进行互操作。

样例代码

下面的例子代码通过注释展示了Elm的基本特征:

-- 这是一个单一行注释。

{-
这是一个多行注释。
它是 {- 可嵌套的。 -}
-}

-- 这里定义叫做greeting的一个值。类型被推论为String。
greeting =
    "Hello World!"

 -- 对顶层声明最好增加类型标注。
hello : String
hello =
    "Hi there."

-- 函数以相同方式声明,具有跟随在函数名字后的实际参数。
add x y =
    x + y

-- 再次的,最好增加类型标注。
hypotenuse : Float -> Float -> Float
hypotenuse a b =
    sqrt (a^2 + b^2)

-- 函数可以柯里化;这里我们柯里化 
-- 乘法中缀算符于一个2。
multiplyBy2 : number -> number
multiplyBy2 =
    (*) 2

-- If表达式用于在Bool值上的分支。
absoluteValue : number -> number
absoluteValue number =
    if number < 0 then negate number else number

 -- 记录用来持有命名字段。
book : { title : String, author : String, pages : Int }
book =
    { title = "Steppenwolf"
    , author = "Hesse"
    , pages = 237 
    }

-- 记录访问通过 . 来进行。
title : String
title =
    book.title

-- 记录访问 . 也可以用作一个函数。
author : String
author =
    .author book

-- 可以通过type关键字建立标签联合。
-- 下列值表示一个二叉树。
type Tree a
    = Empty
    | Node a (Tree a) (Tree a)

-- 可以用过case表达式检测这些类型。
depth : Tree a -> Int
depth tree =
    case tree of
        Empty ->
            0

        Node value left right ->
            1 + max (depth left) (depth right)

参见

  • PureScript:一个强类型的、纯函数式的编译成JavaScript的编程语言。
  • ReasonOCaml的语法扩展和工具链,也可以转译成JavaScript。

引用

  1. ^ Czaplicki, Evan. My Thesis is Finally Complete! "Elm: Concurrent FRP for functional GUIs". Reddit. 
  2. ^ elm/compiler. GitHub. 
  3. ^ Prior Art - Redux. redux.js.org. 
  4. ^ Comparison with Other Frameworks — Vue.js. 
  5. ^ https://github.com/elm/compiler/releases
  6. ^ Elm home page. 
  7. ^ Elm: Concurrent FRP for Functional GUIs (PDF). 
  8. ^ Try Elm. elm-lang.org. [2019-07-24]. (原始内容存档于2017-05-21). 
  9. ^ elm and prezi. elm-lang.org. 
  10. ^ new adventures for elm. elm-lang.org. 
  11. ^ elm/compiler. GitHub. 
  12. ^ repl. elm-lang.org. 
  13. ^ package manager. elm-lang.org. 
  14. ^ Home. elm-lang.org. 
  15. ^ Install. guide.elm-lang.org. 
  16. ^ community created libraries
  17. ^ Ellie
  18. ^ syntax. elm-lang.org. [2013-05-31]. (原始内容存档于2016-03-13). 

外部链接