summaryrefslogtreecommitdiff
path: root/doc/forum/use_withUmask_in_a_property
diff options
context:
space:
mode:
authorJoey Hess2016-06-22 15:28:50 -0400
committerJoey Hess2016-06-22 15:28:50 -0400
commitd2309fce1cab98788260b03bd62dfa737f410050 (patch)
tree0cf60502d7107847c254bbe640b12155eb8ab8b1 /doc/forum/use_withUmask_in_a_property
parent83519ad575d69650a79473dc13b94126e9987255 (diff)
comment
Diffstat (limited to 'doc/forum/use_withUmask_in_a_property')
-rw-r--r--doc/forum/use_withUmask_in_a_property/comment_5_da0074f18fe0ce020325a9f59f44cb1d._comment13
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/forum/use_withUmask_in_a_property/comment_5_da0074f18fe0ce020325a9f59f44cb1d._comment b/doc/forum/use_withUmask_in_a_property/comment_5_da0074f18fe0ce020325a9f59f44cb1d._comment
new file mode 100644
index 00000000..c566bb64
--- /dev/null
+++ b/doc/forum/use_withUmask_in_a_property/comment_5_da0074f18fe0ce020325a9f59f44cb1d._comment
@@ -0,0 +1,13 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 5"""
+ date="2016-06-22T19:24:43Z"
+ content="""
+Unfortunately `withFile` uses IO, instead of being generalized to MonadIO,
+so the approaches that work with `withUmask` don't work with it.
+
+One way is to write a version of withFile that's generalized to MonadIO:
+
+ withFile' :: (MonadIO m, MonadMask m) => FilePath -> IOMode -> (Handle -> m r) -> m r
+ withFile' name mode = bracket (liftIO $ openFile name mode) (liftIO . hClose)
+"""]]