I used to have Email
as type Email = T.Text
.
我将其更改为:
newtype Email = Email { unEmail :: T.Text }
deriving (Show, Eq)
此更改在以下方面产生了错误:
instance Table UserT where
data PrimaryKey UserT f = UserId (Columnar f T.Text) deriving (Generic, Beamable)
primaryKey = UserId . _userAddressEmail
错误:
backend/src/Backend.hs:145:17-22: error:
• Couldn't match type ‘Columnar column T.Text’
with ‘Columnar column Email’
Expected type: Columnar column Email -> PrimaryKey UserT column
Actual type: Columnar column T.Text -> PrimaryKey UserT column
NB: ‘Columnar’ is a non-injective type family
• In the first argument of ‘(.)’, namely ‘UserId’
In the expression: UserId . _userAddressEmail
In an equation for ‘primaryKey’:
primaryKey = UserId . _userAddressEmail
• Relevant bindings include
primaryKey :: UserT column -> PrimaryKey UserT column
(bound at backend/src/Backend.hs:145:4)
|
145 | primaryKey = UserId . _userAddressEmail
| ^^^^^^
我试过了:
instance Table UserT where
data PrimaryKey UserT f = UserId (Columnar f T.Text) deriving (Generic, Beamable)
primaryKey = UserId . (unEmail _userAddressEmail)
但是我得到这个错误:
backend/src/Backend.hs:145:27-51: error:
• Couldn't match expected type ‘UserT column
-> Columnar column T.Text’
with actual type ‘T.Text’
• Possible cause: ‘unEmail’ is applied to too many arguments
In the second argument of ‘(.)’, namely
‘(unEmail _userAddressEmail)’
In the expression: UserId . (unEmail _userAddressEmail)
In an equation for ‘primaryKey’:
primaryKey = UserId . (unEmail _userAddressEmail)
• Relevant bindings include
primaryKey :: UserT column -> PrimaryKey UserT column
(bound at backend/src/Backend.hs:145:4)
|
145 | primaryKey = UserId . (unEmail _userAddressEmail)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
backend/src/Backend.hs:145:35-51: error:
• Couldn't match expected type ‘Email’
with actual type ‘UserT f0 -> Columnar f0 Email’
• Probable cause: ‘_userAddressEmail’ is applied to too few arguments
In the first argument of ‘unEmail’, namely ‘_userAddressEmail’
In the second argument of ‘(.)’, namely
‘(unEmail _userAddressEmail)’
In the expression: UserId . (unEmail _userAddressEmail)
|
145 | primaryKey = UserId . (unEmail _userAddressEmail)
| ^^^^^^^^^^^^^^^^^
I thought unEmail
would unwrap the type?
这是条目:
data UserT f
= User
{ _userAddressEmail :: Columnar f Email
...