Haskell Could not find module `System' - haskell

I'm new with Haskell and have trouble with its package.
I want to import System.Random but
Could not find module `System.Random'
Then I tried to import System but
Could not find module `System'.
It is a member of the hidden package `haskell98-2.0.0.0'.
I tried to search this problem, but those solutions still don't work.
As this said, I tried to install cabal on my Mac OS X using MacPort, but
Error: The following dependencies were not installed: ghc
Error: Status 1 encountered during processing.
I have installed Haskell Platform and can use ghci in command-line.
GHCi, version 7.2.1
Then I tried to use ghc-pkg expose haskell98-2.0.0.0 as this one says.
But this time, I can't even run ghci.
Top level:
Ambiguous interface for `Prelude':
it was found in multiple packages: base haskell98-2.0.0.0
So, what can I do without using cabal?

The System.Random module belongs to the random package, which is no longer included with GHC as of version 7.2.1.
I'm not sure what to do about your Cabal problem, as I'm not familiar with Mac OS X, but I'd recommend getting that to work first. Installing random should then be trivial using Cabal.
As a possible workaround, you might want to consider using an older version of GHC.

the cabal incantation:
cabal install random

The answer here is a little bit dated and would lead to a global install and should be discouraged.
A better approach will be to add the random package as dependency in the .cabal file.
Something like this:
build-depends: base ^>=4.13.0.0 --base package
, random -- random package where System.Random can be found

cabal repl -b random # -b is short for --build-depends
This answer was based on another stackoverflow thread here. Basically it installs the package random as a dependency of your project rather than installing it globally. Packages are installed globally if you just write cabal install random - which we dont usally want.

Related

Can not load a file that uses standard libraries in haskell

Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error.
Chatterbot.hs:3:1: error:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
|
3 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many people speak about stack but it seems annoying and It obviously works for my friend without it.
Thanks in advance
EDIT problem solved. I needed to update cabal then I ran cabal install random and it worked well. Thanks everyone for the help!
If you are using a version of cabal-install >= 3.0 (check with cabal --version), then, instead of creating a cabal package, you can move to an empty folder and type:
cabal install --lib --package-env . random
This creates a .ghc.environment file in the folder. ghci sessions started inside that folder will pick it up, and they will be able to import System.Random.
If that works correctly, you might want to install "random" globally so that any invocation of ghci can use it:
cabal install --lib random
This creates/modifies the global environment file located at ~/.ghc/$ARCH-$OS-$GHCVER/environments/default.
The System.Random module is part of the random package, not of the base package. You thus should install it. If you for example use cabal, you can install it with cabal install random.
If you use Haskell stack for example, you can add it to your package-name.cabal file:
-- …
build-depends:
base >=4.7 && <5
, random >=1.0 && <2

ghc.exe: unable to load package <package_name>

I have recently started learning haskell and have never used the cabal package manager before. I'm currently working on a project that requires me to user the io-streams package.
I of course already have the Haskell Platform installed on my machine. I am currently using the x86_64-core version 8.4.3 installer.
Using a Git Bash terminal on Windows 10, I have created a .cabal-sandbox/ folder (using the cabal sandbox init command), in which to house all of my downloaded packages. I have then run cabal install io-streams to download and install the package from the Hackage site. This has worked fine.
I have now come to writing my code. This is as follows:
module StreamFiles where
import System.IO.Streams.File
main:: IO ()
main = do
putStrLn "some text here"
However, when I come to run this, using the following steps:
1. Run the cabal repl command in the directory where the .cabal-sandbox/ folder is located.
2. I then run the following in Powershell:
Prelude> :l src/fileStreaming/streamfile.hs
[1 of 1] Compiling StreamFile ( src\fileStreaming\streamfile.hs, interpreted )
Ok, one module loaded.
*StreamFile> main
And get the following error:
ghc.exe: | C:\Users\UserName\source\repos\complexHaskell\.cabal-sandbox\x86_64-windows-ghc-8.4.3\network-3.0.1.0-HkosMKsQUp05NPIgp4K8kv\HSnetwork-3.0.1.0-HkosMKsQUp05NPIgp4K8kv.o: unknown symbol `if_nametoindex'
ghc.exe: unable to load package `network-3.0.1.0'
And I cannot work out why. Is this a package problem or is there a step that I have missed when pulling the packages down from the Hackage site?
Do I need to create a .cabal file using the cabal init command and require some dependencies for my imports in there??
Thanks in advance.
C.

cabal could not find module snap.internal.http.server.exception

I have a Haskell desktop application that uses Snap. This application has been building for years now and is an everyday part of our fielded solution. I upgraded to a new development machine some months ago, running Windows 10 with version 7.10.3 of the GHC and 1.22.3.0 of the cabal library with 1.22.4.0 of cabal-install. I have installed version 0.9.8.0 of snap-core and version 0.9.5.1 of snap-server.
When I try and build my application in this environment, it get the following error:
Could not find module `Snap.Internal.Http.Server.Exception'
Perhaps you meant
Snap.Internal.Http.Server.Backend
Snap.Internal.Http.Server.Config
Snap.Internal.Http.Server.Date
I cannot find this module in Hackage. Did something change in Snap since I last built this code? Please, any advice will be appreciated.
Dave
P.S. Here are links to the output of the ghc-pkg list command and to the cabal file for this project.
http://zelda.designacourse.com/dave/ghc-pkg_list.txt
http://zelda.designacourse.com/dave/PreviewWrapper.cabal
With the help of, and gratitude to, epsilonhalbe we found a solution to this problem. I still do not know why the import of Snap.Internal.Http.Server.Exception started to throw an error from the compiler. However, removing that import and adding a type declaration to the variable now allows the code to build without error. i.e. catch ((_ :: IOException) -> return True).

Trying to experiment with data parallel Haskell - but can't get it to install

Is anyone using data parallel Haskell with the 2012.4.0.0 Haskell platform?
I'm a Haskell beginner - but wanted to experiment with switching from lists to parallel arrays.
When I try and run
cabal install dph-examples
I get a build problem with bmp.1.2.3.1:
Codec\BMP.hs:208:11: Not in scope: `BSL.fromStrict'
Sure this is some type of version mismatch - but nor sure what to do.
Any experts out there?
bmp depends on bytestring and binary. binary depends on bytestring itself. Your binary package was built with bytestring-0.9.2.1, the version that came with the platform.
When trying to cabal install bmp, cabal tries to install the latest version for which it can construct a valid install plan without reinstalling libraries (if possible at all). With a binary built with a bytestring-0.9.2.1, that is bmp-1.2.3.1, where the author forgot to bump the lower bound of the bytestring version, so the build fails since fromStrict was added in bytestring-0.10.
You can either install an earlier version of bmp,
cabal install "bmp < 1.2.3"
which is the safe option, or you can rebuild binary against the newer bytestring version. The latter likely will break some other packages depending on binary, so those would have to be rebuilt too. And for a package like bytestring which many other packages depend on, it would also be likely that a similar problem occurs soon again.
Make sure you have bytestring >= 0.10.0.0 installed.

Cannot find out module Data.Colour

I cannot import module Data.Colour, and the error as follow:
Could not find module `Data.Colour'
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Am I missing anything?
A Hayoo! search reveals that this module lives in the colour package, which you presumably don't have installed. To install it, run cabal update followed by cabal install colour.

Resources