Created
March 20, 2023 03:06
-
-
Save nghamilton/b24868e98a1b966a83d5df47674b1d24 to your computer and use it in GitHub Desktop.
Text.append appears broken?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TextIssue where | |
import Data.Text qualified as Text | |
import Data.Text.IO qualified as Text | |
import System.IO | |
import Network.Socket | |
working :: IO () | |
working = do | |
input <- Text.hGetLine stdin | |
Text.putStrLn input | |
-- this works as expected | |
Text.putStrLn $ Text.append "prepends" input | |
-- this works as expected | |
Text.putStrLn $ Text.append input "appends" | |
broken :: IO () | |
broken = do | |
let hints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_NUMERICSERV], addrSocketType = Stream } | |
addr:_ <- getAddrInfo (Just hints) (Just "127.0.0.1") (Just "5000") | |
sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) | |
setSocketOption sock ReuseAddr 1 | |
bind sock (addrAddress addr) | |
listen sock 1 | |
(conn, _) <- accept sock | |
i <- socketToHandle conn ReadWriteMode | |
input <- Text.hGetLine i | |
Text.putStrLn input | |
-- this works as expected | |
Text.putStrLn $ Text.append "prepends" input | |
-- this overwrites the first 7 characters of input with "prepends" | |
Text.putStrLn $ Text.append input "appends" | |
hClose i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment