gpt4 book ai didi

purescript - 错误无法匹配类型

转载 作者:行者123 更新时间:2023-12-03 16:28:24 25 4
gpt4 key购买 nike

我有一个类型:

newtype User = User
{ id :: String
, email :: String
, last_update :: String
}

和一个功能:
import Pux.DOM.HTML (HTML)
import Pux.DOM.HTML.Attributes (key)
import Text.Smolder.HTML as H
import Text.Smolder.HTML.Attributes as A

userRow :: User -> HTML Event
userRow user =
H.tr ! key user.id ! A.className "user-item" $ do
H.td ! key ("email") $ text user.email
H.td ! key ("last_update") $ text user.last_update
H.td ! key ("actions") ! A.className "actions" $ do
H.a ! key ("delete") ! A.className "action-delete" #! onClick (pure $ OpenDeleteModal (show user.id)) $ do
H.span
! A.className "dashicons dashicons-trash"
! A.alt "Delete"
! A.title "Delete"
$ text ""

但是类型不会统一:
268    H.tr ! key user.id ! A.className "user-item" $ do
^^^^

Could not match type

{ id :: String
| t0
}

with type

User

while checking that type User
is at least as general as type { id :: String
| t0
}
while checking that expression user
has type { id :: String
| t0
}
while checking type of property accessor user.id
in value declaration userRow

where t0 is an unknown type

我看不出我做错了什么。在我看来,用户类型有一个“id”成员,它是一个字符串,因此至少与
type { id :: String
| t0
}

最佳答案

User是围绕记录的新类型,因此它将记录包装起来。为了访问记录字段,您首先需要打开它。在您的情况下执行此操作的最简单方法是在 user 上进行模式匹配争论:

userRow :: User -> HTML Event
userRow (User user) =
H.tr ! key user.id ! A.className "user-item" $ do
...

关于purescript - 错误无法匹配类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44417927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com