在 haskell 中使用 >>= 重定向最后一个操作的标准输出

Redirect last action's stdout using >>= in haskell

如何获取之前操作的输出并使用 haskell 中的 >>= 打印出来?

在shell中,就像,

echo "hello world" | { read test; echo test=$test; }

在 haskell 中,我正在寻找类似

的内容
putStrLn "hello world" >>= {x <- getArgs; print x}

getArgs 标准输入必须从 putStrLn 的标准输出中获取输入。

编辑#1, Alexey & aochagavia,感谢您的投入。这行得通。

x :: IO String
x = return "hello world"

main = do
  x >>= print

不,>>= 与标准输出没有任何关系。您可以使用 silently 包中的 capture_ 函数:

 do x <- capture_ (putStrLn "hello world")
    print x

capture_ (putStrLn "hello world") >>= print.