Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell 使用带梁的新类型_Haskell_Haskell Beam - Fatal编程技术网

Haskell 使用带梁的新类型

Haskell 使用带梁的新类型,haskell,haskell-beam,Haskell,Haskell Beam,我以前有Email作为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 =

我以前有
Email
作为
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)
    |                                   ^^^^^^^^^^^^^^^^^
我以为
unEmail
会打开类型

以下是条目:

data UserT f
    = User
    { _userAddressEmail                 :: Columnar f Email
...

您可能打算编写
unEmail
,而不是将其应用于
\u userAddressEmail
——即
UserId。取消邮件_userAddressEmail
而不是
用户ID。(unEmail\u userAddressEmail)
@duplode-我也试过了。结果是:``•无法将“Columnar column Email”类型与“Email”预期类型匹配:UserT column->Email实际类型:UserT column->Columnar column Email```并且
无法将“Columnar column t.Text”类型与“t.Text”预期类型匹配:t.Text->PrimaryKey UserT column实际类型:Columnar column T.Text->PrimaryKey UserT column
查看文档,我怀疑您的意图不可能以这种方式实现。通过映射展开器至少需要使用特定的
f
,这在本文中似乎没有意义。Beam用户指南简要提到,这听起来有些相关;不幸的是,我对Beam还不够熟悉,现在还不能帮上忙。