The following code uses three different methods ( str1 , str2 and str3 ) to replace a string using Data.Text.Lazy.replace . They should give the same result.
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
However, the result of starting the program is:
Hello, Joyce. Hello, <<name>>. Hello, Joyce.
Why is str2 not working correctly? Is there something wrong with the code?
Jan
source share