The description of how to catch exceptions with tryJust is wrong
Niklas Hambüchen
mail at nh2.me
Mon Apr 15 06:11:41 CEST 2013
http://www.haskell.org/ghc/docs/7.6.2/html/libraries/base/Control-Exception.html#g:4
says:
do r <- tryJust (guard . isDoesNotExistError) $ getEnv "HOME"
case r of
Left e -> ...
Right home -> ...
That is misleading, because it doesn't actually allow you to do
something with the error: e is always (), because guard returns unit.
That should be changed in the docs.
"Well", thinks the Haskeller, "I shall use tryJust fromException then",
but that doesn't work because you can't do that for thinks like "file
does not exist", that's why we have isDoesNotExistError after all.
What that example actually means is
do r <- tryJust (\e -> if isDoesNotExistError then Just e else
Nothing) $ getEnv "HOME"
case r of
Left e -> ...
Right home -> ...
How elegant.
More information about the Libraries
mailing list