我有一个类型:
type MenuItem msg
= MenuItem
{ attributes : List (Attribute msg)
, children : List (Html msg)
}
这是NavBar
的一部分。然后我有一个函数renderItems
,它会呈现MenuItem
s:
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
似乎很匹配。
答案 0 :(得分:4)
type alias MenuItem msg
= { attributes : List (Attribute msg)
, children : List (Html msg)
}
与
不同renderItem { attributes, children } =
后者可以按照您的方式进行模式匹配:
renderItem (MenuItem { attributes, children }) =
但前者,因为它包含在数据构造函数中也需要解包:
function getPendingOrdersForUser($username, $connection)
{
$ordersQuery = "SELECT * FROM orders at WHERE at.username=:username;";
$stmt = $connection->prepare($ordersQuery);
$stmt->execute(array(':username' => $username));
$result = !!$stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}