Haskell Elm 中不允许模式匹配?
Haskell pattern matching not allowed in Elm?
在 this Elm tutorial 之后,我假设函数
update : Msg -> Model -> Model
在教程中定义为
update msg model =
case msg of
Increment -> model + 1
Deccrement -> model - 1
Reset -> 0
我想我会用同样的方式定义它,但我更喜欢语法:
update Increment model = model + 1
update Decrement model = model - 1
update Reset model = 0
但是编译不通过,是 Elm 不支持这种语法还是我弄错了?
Elm 的目标之一是使用 consistent style; removing redundant syntax is a conclusion of this. For that reason, you will not find any where
clause and function definitions with multiple variants 也是不允许的。
在 this Elm tutorial 之后,我假设函数
update : Msg -> Model -> Model
在教程中定义为
update msg model =
case msg of
Increment -> model + 1
Deccrement -> model - 1
Reset -> 0
我想我会用同样的方式定义它,但我更喜欢语法:
update Increment model = model + 1
update Decrement model = model - 1
update Reset model = 0
但是编译不通过,是 Elm 不支持这种语法还是我弄错了?
Elm 的目标之一是使用 consistent style; removing redundant syntax is a conclusion of this. For that reason, you will not find any where
clause and function definitions with multiple variants 也是不允许的。