在下面的代码三种不同的方法(str1,str2,和str3使用替换字符串)Data.Text.Lazy.replace.他们应该提供相同的输出.
import Data.Text.Lazy as DTL
str1 :: String
str1 = DTL.unpack $ DTL.replace key value text
where key = DTL.pack "<<name>>"
value = DTL.pack "Joyce"
text = DTL.pack "Hello, <<name>>."
str2 :: String
str2 = DTL.unpack $ DTL.replace key value text
where key = DTL.pack "<<" `DTL.append` DTL.pack "name"
`DTL.append` DTL.pack ">>"
value = DTL.pack "Joyce"
text = DTL.pack "Hello, <<name>>."
str3 :: String
str3 = DTL.unpack $ DTL.replace key value text
where key = DTL.pack $ "<<" ++ "name" ++ ">>"
value = DTL.pack "Joyce"
text = DTL.pack "Hello, <<name>>."
main :: IO ()
main = do putStrLn str1
putStrLn str2
putStrLn str3
Run Code Online (Sandbox Code Playgroud)
然而,运行该程序的结果是:
Hello, Joyce.
Hello, <<name>>.
Hello, Joyce.
Run Code Online (Sandbox Code Playgroud)
为什么str2无法正常工作?代码有什么问题吗?