什么是“!” []” Todomvc中的Elm代码语法的含义 [英] What does "! []" Elm code syntax in Todomvc mean
问题描述
从反应开始,我正在学习理解榆木。
Coming from react, I am learning to understand Elm.
在 Todomvc示例代码,其中包含以下代码段:
In the Todomvc example code, there is the following code snippet:
-- How we update our Model on a given Msg?
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
model ! [] <-- What is this?
我(我想)理解的是,更新
函数接受类型为 Msg
的 msg
和模型$类型为
Model
的c $ c>,并返回一个包含 Model
和的元组Cmd Msg
。
What I (think I) understand, is that the update
function takes in a msg
of type Msg
and a model
of type Model
, and returns a tuple of containing a Model
and a Cmd Msg
.
但是我应该如何阅读返回语句?
But how should I read the return statement?
model ! []
此语句是什么意思?返回模型[某物]空列表?
我在文档中错过了某些解释过的内容吗? (谷歌搜索 elm!并没有帮助我:)
What does this statement mean? return a "model [something] empty list"?
Did I miss something in the docs where this is explained? (Googling "elm !" did not get me far :)
推荐答案
更新为Elm 0.19
Elm 0.19已删除感叹号运算符。现在,您必须手动构造元组,如(模型,Cmd.none)
。
Elm 0.19 has removed the exclamation point operator. You must now construct the tuple manually, as in (model, Cmd.none)
.
原始回答Elm 0.18
模型中的感叹号! []
只是(模型,Cmd.batch [])
的简写函数,这是从典型的<$ c返回的类型。 $ c> update 语句。 在此处定义
The exclamation point in model ! []
is just a short-hand function for (model, Cmd.batch [])
, which is the type returned from typical update
statements. It is defined here
这篇关于什么是“!” []” Todomvc中的Elm代码语法的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!