4

I am trying to write a simple script that takes as input a URL (or set of URLs) and as output it downloads the contents of that page to a file (in particular I am trying to download hundreds of JSON files, which ultimately I wish to diff against other JSON files).

In a file, download.hs, I have import "HTTP" Network.HTTP.

When I run: $ ghc -o download download.hs

I get the following error:

download.hs:24:1: error:
    Could not find module ‘Network.HTTP’
    Perhaps you meant Network.TLS (needs flag -package-key tls-1.5.2)
   |
24 | import "HTTP" Network.HTTP
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^

My GHC version is:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5

I also get errors like:

download.hs:22:1: error:
    Could not load module ‘Control.Concurrent.Async’
    It is a member of the hidden package ‘async-2.2.2’.
    You can run ‘:set -package async’ to expose it.
    (Note: this unloads all the modules in the current scope.)
   |
22 | import "async" Control.Concurrent.Async (mapConcurrently)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think it's possible there have been breaking changes between the ghc versions, and the examples I am finding online to start with may be outdated.

Any pointers on doing started with Haskell, and particularly easy ways to download and diff JSON files in Haskell?

I have been following this example: Running parallel URL downloads in Haskell, this is where I got the code that is erroring now.

8
  • 2
    You appear to simply be missing the packages that define those modules; they need to be installed. Commented Nov 7, 2019 at 17:43
  • 2
    You almost certainly don't need the package name in the import statement: "You probably don’t need to use this feature, it was added mainly so that we can build backwards-compatible versions of packages when APIs change." Commented Nov 7, 2019 at 17:47
  • @chepner Do you mean the "HTTP" isn't necessary in import "HTTP" Network.HTTP, that it could just be import Network.HTTP? Also, how do I install these packages? I know you use cabal, but how do you know which package is missing? Should I try cabal install --lib http? Commented Nov 7, 2019 at 17:54
  • 1
    Unless you have Network.URL in both the HTTP and url packages, GHC is smart enough to find the correct package. Commented Nov 7, 2019 at 17:56
  • I am trying cabal install --lib network now ... I removed "HTTP" and other package names from the imports. Commented Nov 7, 2019 at 17:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.