0
我有一個類型:嘗試在Elm中解構類型時類型不匹配?
type MenuItem msg
= MenuItem
{ attributes : List (Attribute msg)
, children : List (Html msg)
}
這是一個NavBar
的一部分。然後,我有一個函數renderItems
呈現的MenuItem
個清單:
renderItems : List (MenuItem msg) -> Html msg
renderItems items =
ul [ class "nav-list" ] (List.map renderItem items)
renderItems
,你可以看到,來電renderItem
,它看起來像這樣:
renderItem : MenuItem msg -> Html msg
renderItem { attributes, children } =
li [ class "nav-item" ]
[ a ([ class "nav-link" ] ++ attributes)
children
]
但我在這裏得到一個編譯錯誤:
This record is causing problems in this pattern match.
14| renderItem { attributes, children } =
^^^^^^^^^^^^^^^^^^^^^^^^
The pattern matches things of type:
MenuItem msg
But the values it will actually be trying to match are:
{ c | attributes : a, children : b }
Detected errors in 1 module.
任何人都可以爲我解釋這個嗎?我不明白這個錯配。 attributes
和children
似乎相當不錯。