[英]`interact` using Text instead of String
我想重寫interact
函數,但是使用Text
而不是String
。 是否可以使用Data.Text
和/或Data.Text.Lazy
來完成與interact
相同的行為?
例如,當我使用String
運行此程序時:
main = interact (unlines . map f . lines)
where f "hello" = "wassup"
f _ = "wat?"
它等待一行輸入,然后打印出一行作為響應,並等待下一行輸入。 我想編寫相同的代碼並將其用於Text
。
{-# LANGUAGE OverloadedStrings #-}
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as T
textInteract :: (Text -> Text) -> IO ()
textInteract = undefined
main = textInteract (T.unlines . map f . T.lines)
where f "hello" = "wassup"
f _ = "wat?"
但是,不僅是此用例的特例textInteract
。 我希望它有同樣的表現為interact
於所有情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.