【问题标题】:How to compare for equality Data.Text.Internal.Lazy.Text and [Char]?如何比较相等 Data.Text.Internal.Lazy.Text 和 [Char]?
【发布时间】:2018-04-19 03:41:01
【问题描述】:

esqueleto 返回的previousLogItem 数据类型包含Data.Text.Internal.Lazy.Text

import           Data.Text.Lazy                        (pack)

previousLogItem <- select $ from $ \l -> do
        orderBy [desc (l ^. LogItemId)]
        limit 1
        return (l ^. LogItemTitle)

后来我尝试使用以下方法比较 previousLogItemexampleCharList

[Value (pack currentWindowTitle)] == previousLogItem

但这不起作用,因为类型仍然不同:

Couldn't match type ‘Data.Text.Internal.Lazy.Text’
                 with ‘Text’
  NB: ‘Text’ is defined in ‘Data.Text.Internal’
      ‘Data.Text.Internal.Lazy.Text’
        is defined in ‘Data.Text.Internal.Lazy’
    arising from a functional dependency between:
      constraint ‘Database.Esqueleto.Internal.Sql.SqlSelect
                    (SqlExpr (Value Text)) (Value Data.Text.Internal.Lazy.Text)’
        arising from a use of ‘select’
      instance ‘Database.Esqueleto.Internal.Sql.SqlSelect
                  (SqlExpr (Value a)) (Value a)’

【问题讨论】:

    标签: string haskell text type-conversion esqueleto


    【解决方案1】:
    Couldn't match type ‘Data.Text.Internal.Lazy.Text’
                    with ‘Text’
      NB: ‘Text’ is defined in ‘Data.Text.Internal’
        ‘Data.Text.Internal.Lazy.Text’
    

    您使用了错误的Text。检查您的导入。

    【讨论】:

      【解决方案2】:

      编辑:我误读了原始问题

      您是否尝试过使用IsString 类中的fromStringData.Text.Internal.Lazy.Text 应该是 IsString 的一个实例

      旧的(无用的)答案:

      使用Data.Text.Lazy 中的pack 函数将String 转换为Text

      https://hackage.haskell.org/package/text-1.2.3.0/docs/Data-Text-Lazy.html

      【讨论】:

      • 我忘了说,但我使用的包是你提到的那个,例如。来自Data.Text.Lazy。所以这就是我正在做的事情,但它不起作用。
      • 我试过 [Value (fromStrict $ pack currentWindowTitle)] == previousLogItem 但它仍然给出同样的错误:无法将类型'Data.Text.Internal.Lazy.Text'与'Text'匹配
      • 使用 [Value (toStrict $ pack currentWindowTitle)] == previousLogItem 最终起作用了。
      猜你喜欢
      • 2013-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多