简体   繁体   English

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

[英]How to compare for equality Data.Text.Internal.Lazy.Text and [Char]?

The previousLogItem data type returned by esqueleto contains Data.Text.Internal.Lazy.Text 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)

Later I tried to compare previousLogItem with exampleCharList by using: 后来我尝试使用以下方法将previousLogItemexampleCharList进行比较:

[Value (pack currentWindowTitle)] == previousLogItem

But that does not work since the types still differ: 但这不起作用,因为类型仍然不同:

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)’
Couldn't match type ‘Data.Text.Internal.Lazy.Text’
                with ‘Text’
  NB: ‘Text’ is defined in ‘Data.Text.Internal’
    ‘Data.Text.Internal.Lazy.Text’

You're using the wrong kind of Text . 您使用的是错误的Text Check your imports. 检查您的进口。

Edit: I misread the original question 编辑:我看错了原始问题

Have you tried using fromString from the IsString class? 您是否尝试过使用IsString类中的fromString Data.Text.Internal.Lazy.Text should be an instance of IsString Data.Text.Internal.Lazy.Text应该是一个实例IsString

Old (useless) answer: 旧的(无用的)答案:

Use the pack function from Data.Text.Lazy to convert the String to Text 使用Data.Text.Lazypack函数将String转换为Text

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM