如何通过 pcre-heavy 使用 Data.Text

How to work with Data.Text via pcre-heavy

我需要一个简单的示例来通过 prce-heavy 使用 Data.Text。我的示例不起作用,为什么?

{-# LANGUAGE OverloadedStrings, QuasiQuotes, FlexibleContexts #-}

import Data.Text
import Text.Regex.PCRE.Heavy
import qualified Data.Text.IO as TIO

main = do
    let text = "xxx@yahoo.com" :: Text
    let 
      text2 :: Text
      text2 = gsub ([re|xxx|]) ("yyy" :: Text) text
    TIO.putStrLn text2

但与 String 相同的代码运行良好:

{-# LANGUAGE QuasiQuotes, FlexibleContexts #-}

import Text.Regex.PCRE.Heavy

main = do
    let text = "xxx@yahoo.com" :: String
    let 
      text2 :: String
      text2 = gsub ([re|xxx|]) ("yyy" :: String) text
    putStrLn text2

第一个样本错误:

textproblem.hs:11:15: error:
    * No instance for (Data.String.Conversions.ConvertibleStrings
                         Data.String.Conversions.SBS Text)
        arising from a use of `gsub'
    * In the expression:
        gsub
          ((Text.Regex.PCRE.Light.compile
              (Data.String.Conversions.cs ("xxx" :: String))
              [read "PCREOption {unPCREOption = 2048}" :: PCREOption]))
          ("yyy" :: Text)
          text
      In an equation for `text2':
          text2
            = gsub
                ((Text.Regex.PCRE.Light.compile
                    (Data.String.Conversions.cs ("xxx" :: String))
                    [read "PCREOption {unPCREOption = 2048}" :: PCREOption]))
                ("yyy" :: Text)
                text
      In the expression:
        do { let text = ...;
             let text2 :: Text
                 text2
                   = gsub
                       ((Text.Regex.PCRE.Light.compile
                           (Data.String.Conversions.cs (...)) ...))
                       ("yyy" :: Text)
                       text;
             TIO.putStrLn text2 }

将 Haskell 平台重新安装到最新版本并将 pcre 库添加到 msys2 并进行一些实验后,我可以说这个示例运行良好(Haskell 平台在 Windows-7(64 位)上使用 ghc 8.4.3,msys2 通过 pacman 添加 pcre.hlibpcre.a,以及 installed carefully pcre-light and pcre-heavy ).在 Debian Linux(64 位)上它也运行良好,而且没有任何技巧。为什么我看到以前的错误 - 我不知道,也许,除了旧版本的问题。