How can i get the output from previous action and print it using >>= in haskell?
In shell, it is like,
echo "hello world" | { read test; echo test=$test; }
In haskell, i am looking for something like,
putStrLn "hello world" >>= {x <- getArgs; print x}
getArgs stdin must take its input from putStrLn's stdout.
Edit#1, Alexey & aochagavia, thanks for your inputs. This works.
x :: IO String
x = return "hello world"
main = do
x >>= print
No, >>= doesn't have anything to do with stdout. You can use capture_ function from the silently package:
do x <- capture_ (putStrLn "hello world")
print x
or just capture_ (putStrLn "hello world") >>= print.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With