
quoth YueCompl
Catch that error, and copy-and-delete.
I suggest this is typical EAFP (Easier to ask for forgiveness than permission) coding style from Zen of Python http://docs.python.org//glossary.html#term-eafp http://docs.python.org//glossary.html#term-eafp
I'm very curious to know how Haskellers think and do about it?
Is there something close to Zen of Haskell?
For another example, I quote from my man page for access(2), which can be used to determine if the caller has the necessary privilege etc. - " The result of access() should not be used to make an actual access control decision, since its response, even if correct at the moment it is formed, may be outdated at the time you act on it. access() results should only be used to pre-flight, such as when configuring user interface elements or for optimization purposes. The actual access control decision should be made by attempting to execute the relevant system call while holding the applicable credentials, and properly handling any resulting errors; and this must be done even though access() may have predicted success." That particular consideration doesn't apply so much to this case, that I can see anyway, but as a model for how to deal with situations like this it seems sound to me, as long as the operation can be trusted to either work or fail inexpensively and without side effects. You make the intended functionality the main program path; you handle failures as you see fit. However, I have to say, it appears to be less of a Haskell option than in most computer programming languages I'm familiar with. main = catchIOError (rename oldFile newFile) (\ e -> print (ioeGetErrorType e)) ... all I get out of that is "unsupported operation". I see no way to get to the POSIX error value, EXDEV, which isn't one of the few common errors that has a documented Haskell test. In OCaml for example, the well known errors are all enumerated (including EXDEV), but if you need to handle one that isn't, there's EUNKNOWNERR with a value. A casual look at the documentation suggests that while I can catch this error, Haskell doesn't give me the means to identify it. To make the most of my appearance here on haskell-cafe ... I find the notion of a "Zen" of this or that language kind of awkward. I suppose it's one of those usages that has taken on its own diluted popular meaning that has few traces of the original (goes back to "Zen in the Art of Archery"? I don't know.) But as little as the term may intend to refer the actual religious practice, that religious practice is a real thing with many adherents, a complicated doctrine with various schools, a lot of priests - and one where I find it very hard to recognize the appication to computer programming. Donn