Why does Data.Text.Lazy.replace and Data.Text.Lazy.append not work?

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?

+7
source share
3 answers

Thanks for the error message guys. I will look at this and keep track of what I find.

+5
source

Looks like an error in the text library for me.

(I added issue to the tracker error if the author does not visit the stack overflow.)

+4
source

It was a mistake in the search code: at the borders of the template fragment one character (well, a code block) was omitted when creating the skip table, so at some inputs the search window was moved too far, I sent Brian a request for a fix.

Since your templates consist of short literals, if you compiled with optimization, you would not find an error. Good find.

+3
source

All Articles