I can t import Data.Matrix - haskell

I am trying to import Data.Matrix and I am getting this error:
Could not find module `Data.Matrix'
Perhaps you meant Data.Ratio (from base-4.12.0.0)
Use -v to see a list of the files searched for.
|
10 | import Data.Matrix
I don't know if I should install it or something like this and if I should do it, then how?

Related

Which package to install to run this code successfully

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.

Trying to install System.Random on stack

I'm using stack 1.6.1. In src/Main.hs I start with
module Main where
import System.IO
import System.Random
...
I do not use anything from System.Random at this time.
When I run stack ghci I get
/Users/mkaravan/end2end/Music/music/src/Main.hs:4:1: error:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
|
4 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
I've had no luck with any of the following commands:
stack install System.Random
stack install system.random
stack install random
I get this error:
>>> stack install System.Random
Error parsing targets: Directory not found: System.Random
How do I get System.Random to run in Stack?
You probably need to add random to the dependencies section in your package.yaml (or if you are not using hpack, to build-depends in *.cabal). This tells stack that the package depends on the random package, which contains the System.Random module.
Probably the most straightforward command is stack ghci --package random. But in theory stack install random should have worked as well. However, since you haven't included the output from that call, it's not clear what didn't work with it.

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)?

Could not find module, it is a member of the hidden package haskell98

When I try to compile a simple source file with import IO or import Random, the build fails with an error message like this:
Could not find module 'IO'
It is a member of the hidden package 'haskell98-2.0.0.1'
Use -v to see a list of the files searched for
The module names changed at some point. You probably want import System.IO and import System.Random instead.
Here is the module hierarchy for the standard libraries in GHC 7.6.1.

Resources