我需要在我的更新函数中打开一个可能的-value:
update msg model =
case msg of
UpdateMainContent val ->
Maybe.withDefault 100 (Just 42)
model当然,这是虚拟代码,而
Maybe.withDefault 100 (Just 42)是直接从可能的文件上拿出来的,不应该做任何事情。编译器抱怨说:
Detected errors in 1 module.
-- TYPE MISMATCH ----------------------------------- ./src/Review/Form/State.elm
The 1st argument to function `withDefault` is causing a mismatch.
15|> Maybe.withDefault 100 (Just 42))
16| -- Maybe.withDefault 100 (model.activeItem)
17| model
Function `withDefault` is expecting the 1st argument to be:
a -> b
But it is:
number为什么它说"withDefault“期待第一个参数是
a -> b当它被定义为
a -> Maybe a -> a在文件里?
发布于 2016-08-09 08:21:05
你不小心离开了model
UpdateMainContent val ->
Maybe.withDefault 100 (Just 42)
model -- <-- here这使得类型推断算法认为Maybe.withDefault 100 (Just 42)应该计算为一个可以接受model参数的函数。要做到这一点,它希望100和42是函数,但它们不是,所以它告诉您。
看看这样做的例子也许会有帮助:
f : Int -> Int
f x = x + 1
Maybe.withDefault identity (Just f) 0 这将评估为1。
https://stackoverflow.com/questions/38844342
复制相似问题