尝试在Elm中解构类型时类型不匹配?

尝试在Elm中解构类型时类型不匹配?,elm,type-mismatch,Elm,Type Mismatch,我有一种类型: type MenuItem msg = MenuItem { attributes : List (Attribute msg) , children : List (Html msg) } 这是导航栏的一部分。然后我有一个函数renderItems,它呈现MenuItems的列表: renderItems : List (MenuItem msg) -> Html msg renderItems items =

我有一种类型:

type MenuItem msg
    = MenuItem
        { attributes : List (Attribute msg)
        , children : List (Html msg)
        }
这是导航栏的一部分。然后我有一个函数
renderItems
,它呈现
MenuItem
s的列表:

renderItems : List (MenuItem msg) -> Html msg
renderItems items =
    ul [ class "nav-list" ] (List.map renderItem items)
可以看到,
renderItem
,调用
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.
有人能帮我解释一下吗?我不理解这种不匹配<代码>属性和子项似乎匹配得很好

type MenuItem msg
    = MenuItem
        { attributes : List (Attribute msg)
        , children : List (Html msg)
        }
有别于

type alias MenuItem msg
    = { attributes : List (Attribute msg)
      , children : List (Html msg)
      }
后者可以像您那样进行模式匹配:

renderItem { attributes, children } =
但前者,因为它是包装在数据构造函数中的,所以也需要展开:

renderItem (MenuItem { attributes, children }) =
有别于

type alias MenuItem msg
    = { attributes : List (Attribute msg)
      , children : List (Html msg)
      }
后者可以像您那样进行模式匹配:

renderItem { attributes, children } =
但前者,因为它是包装在数据构造函数中的,所以也需要展开:

renderItem (MenuItem { attributes, children }) =