Which package to install to run this code successfully - haskell

I am trying following simple code from here :
import Data.GI.Base
import qualified GI.Gtk as Gtk
main :: IO()
main = do
Gtk.init Nothing
Gtk.main
However, I am getting following error:
Could not find module `Data.GI.Base'
Use -v to see a list of the files searched for.
|
1 | import Data.GI.Base
| ^^^^^^^^^^^^^^^^^^^
simplewin.hs:2:1: error:
Could not find module `GI.Gtk'
Use -v to see a list of the files searched for.
|
2 | import qualified GI.Gtk as Gtk
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Following attempts to install packages do not find any matches:
>cabal list Data.GI.Base
No matches found.
>cabal list GI.Gtk
No matches found.
Which packages do I install with cabal to correct above errors?

You can search Stackage (the FPComplete package repository, the de-facto standard for Haskell) for the module, type, or function name.
For example, when I type in Data.GI.Base, I get its documentation page, which tells me (at the very top) that the module is available in the package haskell-gi-base.
Not every package is available on Stackage though. If you can't find something, try Hackage next. It's less regulated and controlled, but has more stuff because of it.

Related

Could not load module 'System.Random'

I could not add System.Random module to use it my source haskell file.
import System.Random
This is the error produced by stack ghc:
/Users/admin1/Haskell/PROJECTS/L4/src/Lib4.hs:32:1: error:
Could not load module ‘System.Random’
It is a member of the hidden package ‘random-1.1’.
You can run ‘:set -package random’ to expose it.
(Note: this unloads all the modules in the current scope.)
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
32 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
Failed, five modules loaded.
Thank you very much in advance.
P.S. I am using Stack and GHC versions: Version 2.3.1, Git revision x86_64 hpack-0.33.0, ghc-8.8.3 on Mac OSX
As the error says:
It is a member of the hidden package ‘random-1.1’.
This likely means that you did not list it in the build-depends, and thus it is not exposed to your modules.
You can alter the .cabal file, and add it, for example:
-- project.cabal file
-- …
executable …
-- …
build-depends:
base >= 4.7 && < 5
, random >= 1.1
-- , …

Haskell: same module found twice - "Ambiguous module name"

I have the following import in a haskell file. I'm using cabal.
import Network.Wai (Application, Response, rawPathInfo, responseFile, responseLBS, requestBody)
But I'm getting this error when I try to build the file:
Error: Ambiguous module name ‘Network.Wai’:
it was found in multiple packages: wai-3.2.2.1 wai-3.2.2.1
Note that the multiple packages are exactly the same. Something like -XPackageImports doesn't work here, because for some reason the same package is installed twice.
I opened up /Users/<user>/.cabal/store/ghc-8.6.5/package.db and sure enough, there were two "w" (wai) packages with the same version but different hashes. I deleted one and this didn't fix it.

Which library is the simpleHTTP function in?

I have installed using cabal install network, HTTP, http-conduit, and http-client. When I run ghc it still throws this error:
testRun.hs:1:1: error:
Could not find module `Network.HTTP.Simple'
Perhaps you meant
Network.HTTP.Base (from HTTP-4000.3.12)
Network.HTTP.Cookie (from HTTP-4000.3.12)
Network.HTTP.Stream (from HTTP-4000.3.12)
Use -v to see a list of the files searched for.
|
1 | import Network.HTTP.Simple
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
or this error if I use Conduit:
testRun.hs:1:1: error:
Could not find module `Network.HTTP.Conduit'
Perhaps you meant Network.HTTP.Cookie (from HTTP-4000.3.12)
Use -v to see a list of the files searched for.
|
1 | import Network.HTTP.Conduit (simpleHttp)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
What do in need to install?
It's using a different approach (Stack as a script interpreter), but most likely the following command will run the script with the necessary libraries available:
stack --resolver lts-12.9 script testRun.hs

Finding explicit imports for ghc's -Wmissing-import-lists

GHC generates warnings when there are implicit imports (see below). The goal is to replace these with explicit imports. Is there an automated way to generated the list (instead of manually finding it in code)?
/Users/srid/code/slownews/backend/src/SlowNews/Main.hs:10:1: warning: [-Wmissing-import-lists]
The module ‘Control.Exception’ does not have an explicit import list
|
10 | import Control.Exception
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/srid/code/slownews/backend/src/SlowNews/Main.hs:13:1: warning: [-Wmissing-import-lists]
The module ‘Control.Monad.IO.Class’ does not have an explicit import list
|
13 | import Control.Monad.IO.Class
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
GHC has a -ddump-minimal-imports flag which will do the trick.
There's an open pull request un importify tool which I'm working on. After this is done you will be able to convert implicit imports to explicit automatically:
https://github.com/serokell/importify/pull/82
The Haskell Tools project has some nice looking tooling for that. Apparently it works in Atom but I couldn't get it to work with atom or atom-beta on macOS. However, it does work at the command line. I have a simple example stack project set up. The Main.hs uses an explicit import list:
module Main where
import System.Environment
doMain = print =<< getEnvironment
main = doMain
BTW, I installed the Haskell Tools with:
$ stack install haskell-tools-daemon haskell-tools-cli fswatch
Then execute:
$ ht-refact -e 'ProjectOrganizeImports' .
Now git tells me that I have the following diff:
-import System.Environment
+import System.Environment (getEnvironment)
Check out the Haskell Tools website for an interactive example of how it should work in an editor. Looks like a very promising set of refactoring tools.

Where can I see how Haskell modules have been restructured?

Since the recent update of Haskell on my system, I'm getting numerous import errors. For example, I get:
Crypto/Enigma.hs:64:1: error:
Could not find module ‘Data.List.Split’
Use -v to see a list of the files searched for.
|
64 | import Data.List.Split (splitOn)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Crypto/Enigma.hs:70:1: error:
Could not find module ‘Data.String.Utils’
Use -v to see a list of the files searched for.
|
70 | import Data.String.Utils (replace)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Is there a place I can go to see what changes have been made to the package structure in the recent update? Im particular, where the functions I'm looking for have gone (to what modules)?

Resources