我需要解開一個可能 - 值在我更新功能之一:榆樹Maybe.withDefault
update msg model =
case msg of
UpdateMainContent val ->
Maybe.withDefault 100 (Just 42)
model
這當然是假的代碼和
Maybe.withDefault 100 (Just 42)
取直出的documentation for Maybe,不應該實際上做任何事情。編譯器抱怨,說:
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
在
文檔?
看起來你有一些奇怪的語法錯誤在你的代碼和編譯器無法識別它。嘗試換行'(Maybe.withDefault 100(只是42))'或將更多代碼添加到您的示例中。 – halfzebra
@halfzebra給出了完全相同的錯誤。我不想粘貼完整的代碼路徑,因爲它的大,嵌套和模塊化,這將使問題有點具體。但是我可以說「val」只是一個簡單的字符串進來。所以你說的是我可以在上面的代碼之外導致錯誤的語法錯誤?我試着澄清一下我的問題。 – swelet