Home > Software engineering >  real world haskell compile fail tempfile.hs
real world haskell compile fail tempfile.hs

Time:12-25

Compile the ch07 tempfile.hs, it report below error. how to fix it?

        import System.IO
        import System.Directory(getTemporaryDirectory, removeFile)
        import System.IO.Error(catch)
        import Control.Exception(finally)

    tempfile.hs:4:24: error:
       Module System.IO.Error does not export catch
      |
    4 | import System.IO.Error(catch)
      |                        ^^^^^

CodePudding user response:

I think you don't necessarily have to give up on reading Real World Haskell. I think you can easily fix the most common "Foo does not export bar" errors by looking up bar in Hoogle results for "catch"

Hoogle cannot find all possible results, but it should find the results from the most well-maintained and the most popular packages.

The words of the green line of text below each result which start with a lowercase letter are the names of the packages that export this function. The base package is one of the most fundamental package, so if your function is defined there, then you should probably choose that version. You can see that that is the case for the first result.

The rest of the green line of text are the modules from which the function is exported. For the first result that is Control.Exception, Control.Exception.Base, and GHC.IO. Modules starting with GHC should be avoided if possible, these require specific implementation details of the GHC compiler, which is not a big problem, but it also indicates that it is probably not a standard module. Additionally, I would recommend choosing the name with the fewest .'s, so Control.Exception and not Control.Exception.Base, because those are the most general modules.

Another thing that you should watch out for are modules that contain the name Internal. An example can be seen in the green line below the second result, namely System.Directory.Internal.Prelude. These modules are have no guarantee to be stable across versions of the package that contains them, so you should also avoid these unstable modules.

So, in this case you can choose to import catch from Control.Exception. To do that you can just remove the line with System.IO.Error and add catch to the list of imports from the Control.Exception module:

import Control.Exception(finally, catch)
  • Related