如何比较Data.Text.Internal.Lazy.Text和[Char]的相等性?

时间:2018-04-19 03:41:01

标签: string haskell text type-conversion esqueleto

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)’

2 个答案:

答案 0 :(得分:2)

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种类。检查你的进口。

答案 1 :(得分:0)

编辑:我误读了原来的问题

您是否尝试过使用fromString课程中的IsStringData.Text.Internal.Lazy.Text应该是IsString

的一个实例

老(没用)回答:

使用pack中的Data.Text.Lazy功能将String转换为Text

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