I know I can use interact :: (String -> String) -> IO () to conveniently read from stdin and write to stdout in a simple Haskell program (see http://learnyouahaskell.com/input-and-output).
Now I would like to add command-line arguments to make my simple program "configurable".
Is there a way to do this and still use interact (so as to obtain a configurable program with minimum effort)?
This can be done by "sequencing" IO computations with do and use getArgs before using interact:
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
interact (<whatever using args>)
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