2
我想了解榆樹郎,我有一些問題處理我的小應用程序的更新部分。榆樹在更新列表中添加項目
實際上,我希望當我點擊一個按鈕時,它會在列表中添加一個新用戶,這非常簡單,沒有任何意義,但我需要理解。
現在,我米有下面的代碼:
main =
Html.beginnerProgram { model = model, view = view, update = update }
type Msg = AddUser
type alias User =
{
username : String,
firstname: String,
lastname: String
}
model: List User
model =
[]
update: Msg -> User -> List User -> List User
update msg user userList =
case msg of
AddUser ->
user::userList
而我會具有以下錯誤:
-- TYPE MISMATCH ------------------------------------------------------ main.elm
The argument to function `beginnerProgram` is causing a mismatch.
5| Html.beginnerProgram { model = model, view = view, update = update }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Function `beginnerProgram` is expecting the argument to be:
{ ..., update : Msg -> List User -> List User }
But it is:
{ ..., update : Msg -> User -> List User -> List User }
Hint: Problem in the `update` field. I always figure out field types in
alphabetical order. If a field seems fine, I assume it is "correct" in
subsequent checks. So the problem may actually be a weird interaction with
previous fields.
其實什麼我米目前從更新功能的理解是:
- 在返回接受用戶的函數的第一個函數中帶一個Msg
- 此功能(接受用戶)返回函數接受用戶的列表(以使操作用戶::用戶列表)
- 這最後一個函數返回用戶的列表而我會做
但我在這種情況下我不能得到我錯誤的地方。
你能幫我嗎?