Skip to content

Instantly share code, notes, and snippets.

@joncol
Created January 4, 2025 11:56
Show Gist options
  • Select an option

  • Save joncol/d8dc03e08d998c6b85b6c31dce80aa8d to your computer and use it in GitHub Desktop.

Select an option

Save joncol/d8dc03e08d998c6b85b6c31dce80aa8d to your computer and use it in GitHub Desktop.
main :: IO ()
main = do
evalContT $ do
a <- ContT $ withFile "a.txt" ReadMode
b <- ContT $ withFile "b.txt" ReadMode
aContents <- liftIO $ hGetContents a
bContents <- liftIO $ hGetContents b
liftIO . putStrLn $ "contents of a: " <> show aContents
liftIO . putStrLn $ "contents of b: " <> show bContents
@joncol
Copy link
Copy Markdown
Author

joncol commented Jan 4, 2025

When the file a.txt exists, but the file b.txt does not exist, the following error is reported when running the above:

my-exe: a.txt: withFile: does not exist (No such file or directory)

It would be less confusing if that error said that b.txt did not exists, instead of complaining about a.txt. What am I missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment