-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
Silently is a package that allows you to run an IO action and prevent it from writing to stdout, or any other handle, by using "silence". Or you can capture the output for yourself using "capture". | ||
|
||
For example, in GHCI | ||
For example; the program | ||
|
||
Prelude> :m + System.IO.Silently | ||
Prelude System.IO.Silently> :m + System.IO | ||
Prelude System.IO.Silently System.IO> | ||
Prelude System.IO.Silently System.IO> print 1 >> silence (print 2 >> return "kittens!") >> print 3 | ||
1 | ||
3 | ||
Prelude System.IO.Silently System.IO> print 1 >> capture (hPutStrLn stdout "2" >> hPutStrLn stderr "3" >> return "puppies!") | ||
1 | ||
3 | ||
("2\n","puppies!") | ||
Prelude System.IO.Silently System.IO> print 1 >> hSilence [stderr] (hPutStrLn stdout "2" >> hPutStrLn stderr "3" >> return "kittens!") >> print 4 | ||
1 | ||
2 | ||
4 | ||
Prelude System.IO.Silently System.IO> print 1 >> hCapture [stdout,stderr] (hPutStrLn stdout "2" >> hPutStrLn stderr "3" >> return "puppies!") | ||
1 | ||
("2\n3\n","puppies!") | ||
import System.IO.Silently | ||
|
||
main = do | ||
putStr "putStrLn: " >> putStrLn "puppies!" | ||
putStr "silenced: " >> silence (putStrLn "kittens!") | ||
putStrLn "" | ||
(captured, result) <- capture (putStr "wookies!" >> return 123) | ||
putStr "captured: " >> putStrLn captured | ||
putStr "returned: " >> putStrLn (show result) | ||
|
||
will print | ||
|
||
putStrLn: puppies! | ||
silenced: | ||
captured: wookies! | ||
returned: 123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters