Redirect last stdout action with>> = in haskell

How can I get the result of the previous action and print it using >>=haskell?

In a shell, it looks like

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

In haskell, I'm looking for something like

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

getArgs stdin should receive its data from putStrLn stdout.

Edit # 1, Alexey and aochagavia, thanks for your submissions. It works.

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

main = do
  x >>= print
+4
source share
1 answer

No, >>=it has nothing to do with stdout. You can use the function capture_in silently package :

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

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

+7
source

All Articles