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

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.

Related

Haskell Language Server in VS code shows 'could not find module' Error

I have the following imports in my file
import Control.Applicative (Applicative(liftA2))
import Control.Monad ( guard )
import qualified Data.Vector as V
and I get the error that reads could not find module 'Data.Vector'
The module is installed. I have vector in dependencies and the program builds fine. I just can't get rid of the error in VS Code.
What extra installations do I have to do to fix this?
I have tried:
cabal install vector --lib
Have you tried?
cabal install vector --lib

How to diagnose "Perhaps you need to add xxx to the build-depends in your .cabal file", when it is already in the cabal file?

I think the only interesting bits are my imports and my cabal file. Here are the imports and the demonstration of how I would use the problematic import (Database.CQL.IO.Log).
module FDS.Database.Cassandra where
import Prelude hiding(init)
import Database.CQL.IO as Client hiding(Logger)
import Database.CQL.IO.Log as CQLLog
import qualified Database.CQL.Protocol as CQL
import Numeric.Natural
import System.Logger (Logger)
cqlLogger :: Logger -> CQLLog.Logger
cqlLogger logger = undefined
However, I get the error:
src/FDS/Database/Cassandra.hs:7:1: error:
Could not load module `Database.CQL.IO.Log'
It is a member of the hidden package `cql-io-1.1.0'.
Perhaps you need to add `cql-io' to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
|
7 | import Database.CQL.IO.Log as CQLLog
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But as we can see from the cabal file, it is there:
library
ghc-options: -Wall -Wtabs -Wincomplete-record-updates
default-extensions:
OverloadedStrings
exposed-modules:
FDS
, FDS.Config.Core
, FDS.Config.Dhall
, FDS.Data.Util
, FDS.Database.Cassandra
other-modules:
FDS.Data.Hobo.Defs
build-depends:
prelude
, base-noprelude ^>=4.12
, bytestring ^>=0.10.8.2
, conduit ^>=1.3.1
, containers ^>=0.6
, cql ^>=4.0.1
, cql-io ^>=1.1.0
One thing to note, I do have cql-io in my extra-deps in stack.yaml, as the latest version wasn't yet in LTS.
Q&A from Comments
Q Are there other components in your cabal file (e.g. executables, benchmarks, test suites)?
A Yes
Q Do they also use FDS.Database.Cassandra (but perhaps without depending on cql-io)?
A Not yet, but plan to later. So I haven't touched the other components yet.
Q Does the version of cql-io chosen by your build tool still export Database.CQL.IO.Log?
A It seems to do so.
Q What is the exact command you are running when you see that error?
A stack --nix build The only interesting bit that --nix is doing (AFAIK) is pulling in required system packages, e.g., OpenSSL.
The comments above were very insightful for the general case of the question (as posed); the answer being, sub-libraries that are recently supported by cabal may not have visibility: true declared.
But in my specific case, the answer is to look at the problematic library's re-exports. I could get around this issue because the cql-io authors re-exported Logger (..) and LogLevel(..) from the main library.
So that would allow me to write my code.
An even better answer that is very specific to my situation, as I was trying to use TinyLog, is that there is a library for that already ... here is the code from that library that demonstrates how to get around the issue (and solves the problem for me completely, as I now shouldn't have to write any code).
Here is the relevant excerpt:
module Database.CQL.IO.Tinylog (mkLogger) where
import Data.ByteString.Builder
import Data.ByteString.Lazy (ByteString)
import Database.CQL.IO (Logger (..), LogLevel (..))
import Database.CQL.IO.Hexdump
import qualified Data.ByteString.Lazy as L
import qualified System.Logger as Tiny
-- | Create a cql-io 'Logger' that delegates log messages to
-- the given tinylog 'Tiny.Logger'. Requests and responses are
-- logged on 'Tiny.Trace' level.
mkLogger :: Tiny.Logger -> Logger
mkLogger l = Logger
{ logMessage = tinylogMessage l
, logRequest = tinylogRequest l
, logResponse = tinylogResponse l
}
And here is how I adjusted my imports in the example above to confirm and get GHC happy (though I will scrap this now in favor of using cql-io-tinylog):
import Prelude hiding(init, log)
import Database.CQL.IO hiding(Logger)
import qualified Database.CQL.IO as CQLIO
import qualified Database.CQL.Protocol as CQL
import Numeric.Natural
import System.Logger hiding(defSettings)

Haskell module import path navigation

I have a directory structure which goes something like this
a
- a.hs
- b
-- b.hs
- c
-- c.hs
I want to import c.hs in to b.hs but I can't work out how to go up a directory and in to b. Typically this would be something like ../c/c.hs.
What is the Haskell way to do this?
Typically you don't save "just code" but modules module ModuleName where. Modules are saved under a file name and path that reflects the module name so you'd have file ADirectory/A.hs (note the capital letter at the start) which starts with module ADirectory.A where and same with the others.
After writing your code people collect the modules into the package.
Sometimes off-handedly called "cabalization" due to using the cabal-install tool (or the alternative, stack), this can be done with cabal init and making sure your cabal file lists each module.
Inside modules such as the file ADirectory/A.hs, you can import the other modules. For example A can import B via import BDirectory.B.
Finally, if it isn't already obvious, the import statements refer to modules which the compiler must already have installed. It isn't possible to import something based on a file system path.

import a whole module at one time with Haskell

I'm embarrassed with a library problem with Haskell.
I finished a library made of several files
src/MyLib/Firstbib.hs
src/MyLib/Secondbib.hs
...
src/MyLib/Lastbib.hs
At this time, After cabal install I can import each file separatly with
import MyLib.Firstbib
import MyLib.Secondbib
import MyLib.Lastbib
every thing is OK
Now, I would like to import all these part of MyLib in a simple import :
import MyLib
and I can't reach to make it.
I tried to create a file named src/MyLib.hs containing :
module MyLib where
import MyLib.Types
import MyLib.Functions
import MyLib.Algo.Line
import MyLib.Algo.Point
and expose it with Cabal
Library
-- Modules exported by the library.
Hs-Source-Dirs: src
Exposed-modules: MyLib
, MyLib.Functions
, MyLib.Types
, MyLib.Algo.Line
, MyLib.Algo.Point
but it doesn't work.!
What it the correct way to import many files with only one module import (as for Gtk2Hs for example)?
This is how MyLib should look like -- maybe with different indentation:
module MyLib
(module MyLib.Types
,module MyLib.Functions
,module MyLib.Algo.Line
,module MyLib.Algo.Point
) where
import MyLib.Types
import MyLib.Functions
import MyLib.Algo.Line
import MyLib.Algo.Point
What happens is that when you put a module like that in your export list, you export all the symbols that your module knows about it.
You could potentially scope what part of this module you export, for example:
module ExampleLib
(module Data.Maybe
) where
import Data.Maybe (fromJust)
The above will just re-export fromJust from Data.Maybe, not the whole Data.Maybe module.

haskell import problem

I have a module "Dictionary", declared in a file "Dictionary.hs".
in the same directory i have a file "Def.hs" which imports Dictionary
here's the error i get
... /edsl/Def.hs:4:7:
Could not find module `Dictionary':
locations searched:
Dictionary.hs
Dictionary.lhs
... /edsl/Dictionary.hs is there. it's permissions are such that it can be written to or read from by anyone.
i really have no idea why i can't import. i'm using ghc 6.12.1 on mac os x 10.5.8
edit
here's the relevant code
in Dictionary.hs
module Dictionary where
...
and in in Def.hs
module Def where
import Control.Exception
import Data.Dynamic
import Dictionary
...
am i just defining the module incorrectly? i want to export all symbols.
i just found the problem. i'm using komodo edit, and the command the i created to load a file into ghci doesn't change the working directory.
doh.

Resources