Couldn't import and download Data.List.Ordered in Haskell - haskell

I'm too beginner in Haskell and I wrote a simple program that imports Data.List.Ordered, when I run the program this error appears:
test.hs:3:1: error:
Could not find module `Data.List.Ordered'
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Data.List.Ordered ( isSorted, nub )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Then I tired to download the package using the following command:
cabal install --lib --package-env . ordered
but It didn't work as well
C:\WINDOWS\system32>cabal install --lib --package-env . ordered
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- ordered-0.1 (lib:ordered) (requires build)
Starting ordered-0.1 (all, legacy fallback)
Building ordered-0.1 (all, legacy fallback)
Failed to build ordered-0.1.
Build log (
C:\Users\reema\Desktop\Haskell\cabal\logs\ghc-8.10.7\ordered-0.1-e612131c8de88f5b62dca269575aa8273bdac512.log
):
Preprocessing library for ordered-0.1..
Building library for ordered-0.1..
[1 of 3] Compiling Data.Poset.Internal ( Data\Poset\Internal.hs, dist\build\Data\Poset\Internal.o )
Data\Poset\Internal.hs:32:10: error:
* No instance for (Semigroup PosetOrd)
arising from the superclasses of an instance declaration
* In the instance declaration for `Monoid PosetOrd'
|
32 | instance Monoid PosetOrd where
| ^^^^^^^^^^^^^^^
cabal-3.6.2.0.exe: Failed to build ordered-0.1. See the build log above for details.
These versions I'm using:
GHCi, version 8.10.7
Cabal, version3.6.2.0

Related

Error with cabal install while building lib

I'm trying to install FunGEn with cabal install --allow-newer=all FunGEn (I added --allow-newer=all bcs it was having trouble with dependencies). After a few tries of running this I keep getting the same error message:
Resolving dependencies...
Build profile: -w ghc-9.2.1 -O1
In order, the following will be built (use -v for more details):
- text-1.2.3.2 (lib) (requires build)
- OpenGLRaw-3.3.4.1 (lib) (requires build)
- GLURaw-2.0.0.5 (lib) (requires build)
- OpenGL-3.0.3.0 (lib) (requires build)
- GLUT-2.7.0.16 (lib) (requires build)
- FunGEn-1.1.1 (lib) (requires build)
- FunGEn-1.1.1 (exe:fungen-worms) (requires build)
- FunGEn-1.1.1 (exe:fungen-hello) (requires build)
- FunGEn-1.1.1 (exe:fungen-pong) (requires build)
Starting text-1.2.3.2 (lib)
Building text-1.2.3.2 (lib)
Failed to build text-1.2.3.2.
Build log (
C:\cabal\logs\ghc-9.2.1\text-1.2.3.2-69443a9a6ed6dc92878e4d67ead16d149c2e752e.log
):
Preprocessing library for text-1.2.3.2..
Building library for text-1.2.3.2..
[ 1 of 44] Compiling Data.Text.Encoding.Error ( Data\Text\Encoding\Error.hs, dist\build\Data\Text\Encoding\Error.o )
[ 2 of 44] Compiling Data.Text.Internal.Builder.Int.Digits ( Data\Text\Internal\Builder\Int\Digits.hs, dist\build\Data\Text\Internal\Builder\Int\Digits.o )
[ 3 of 44] Compiling Data.Text.Internal.Builder.RealFloat.Functions ( Data\Text\Internal\Builder\RealFloat\Functions.hs, dist\build\Data\Text\Internal\Builder\RealFloat\Functions.o )
[ 4 of 44] Compiling Data.Text.Internal.Encoding.Utf16 ( Data\Text\Internal\Encoding\Utf16.hs, dist\build\Data\Text\Internal\Encoding\Utf16.o )
Data\Text\Internal\Encoding\Utf16.hs:32:23: error:
* Couldn't match expected type `Word#' with actual type `Word16#'
* In the first argument of `word2Int#', namely `a#'
In the expression: word2Int# a#
In an equation for `x#': !x# = word2Int# a#
|
32 | !x# = word2Int# a#
| ^^
Data\Text\Internal\Encoding\Utf16.hs:33:23: error:
* Couldn't match expected type `Word#' with actual type `Word16#'
* In the first argument of `word2Int#', namely `b#'
In the expression: word2Int# b#
In an equation for `y#': !y# = word2Int# b#
|
33 | !y# = word2Int# b#
| ^^
cabal.exe: Failed to build text-1.2.3.2 (which is required by exe:fungen-worms
from FunGEn-1.1.1, exe:fungen-hello from FunGEn-1.1.1 and others). See the
build log above for details.
Can somebody please explain what's going wrong here, and possibly how to fix it? Thank You!
These particular errors are coming from using GHC 9.2 to compile code that is not compatible with GHC 9.2. The package you're trying to use compiles okay with GHC 9.0 (no --allow-newer needed), which I suggest you to use. It is very easy to switch between compiler versions these days using GHCup.
Another option, not requiring switching the compiler, is, as you do, to apply --alow-newer in some way. You should understand that it's a very dangerous weapon better used only in cases when you understand how dependency solving works, and have sufficient experience with it and cabal in general. The variant that worked for me:
cabal update
cabal install --allow-newer=bytestring FunGEn
Another possible issue in your approach is that cabal install (without appropriate switches on top of it) will only give you executables in the package, not the library. It's okay if that's what you want.

How to run shake without stack

I created the recommended build.sh file from the "Running" section of the Shake manual:
#!/bin/sh
mkdir -p _shake
ghc --make Shakefile.hs -v -rtsopts -threaded -with-rtsopts=-I0 -outputdir=_shake -o _shake/build && _shake/build "$#"
but running that script gives the following error:
[1 of 1] Compiling Main ( Shakefile.hs, _shake/Main.o )
Shakefile.hs:1:1: error:
Could not find module ‘Development.Shake’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
1 | import Development.Shake
| ^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:2:1: error:
Could not find module ‘Development.Shake.Command’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
2 | import Development.Shake.Command
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:3:1: error:
Could not find module ‘Development.Shake.FilePath’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Development.Shake.FilePath
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Shakefile.hs:4:1: error:
Could not find module ‘Development.Shake.Util’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
4 | import Development.Shake.Util
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I did cabal v2-install shake --installpath=bin, but still get the same error afterwards. I also tried bin/shake but get the same error.
I tried adding -package shake to the ghc command in the build.sh, but get this error:
<command line>: cannot satisfy -package shake
(use -v for more information)
Adding -v as suggested gives this error:
Glasgow Haskell Compiler, Version 8.8.4, stage 2 booted by GHC version 8.8.3
Using binary package database: /Users/avh4/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/package.conf.d/package.cache
package flags [-package shake{package shake True ([])}]
loading package database /Users/avh4/.ghcup/ghc/8.8.4/lib/ghc-8.8.4/package.conf.d
<command line>: cannot satisfy -package shake
(use -v for more information)
What is the correct way to use Shake without Haskell stack (preferably using only ghc 8.8 installed with ghcup and/or with cabal-install v2 commands)?
I figured out I need to use the --lib flag with cabal new-install otherwise only the shake binary gets installed.
After running cabal new-install --lib shake, the original build.sh script with the addition of -package shake to the ghc arguments now works! And runhaskell -package shake Shakefile.hs also works now.

flycheck-haskell and doctest don't work on Cabal 3.0 v2-build project

I tried to create a Nix-style local build (v2-build) project on Cabal 3.0.
But several development tools (flycheck-haskell and doctest) don't work.
They worked on new-build project on Cabal 2.4.
Error message says they cannot find dependencies, as far as I read.
$ cabal v2-clean
$ cabal v2-build
$ cabal v2-test
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
- hstest9-0.1.0.0 (test:doctestd) (first run)
Configuring test suite 'doctestd' for hstest9-0.1.0.0..
Preprocessing test suite 'doctestd' for hstest9-0.1.0.0..
Building test suite 'doctestd' for hstest9-0.1.0.0..
[1 of 1] Compiling Main ( test/doctest-driver.hs, /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd-tmp/Main.o )
Linking /Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/build/doctestd/doctestd ...
Running 1 test suites...
Test suite doctestd: RUNNING...
/Users/user/work/hstest9/src/MyLib.hs:3:1: error:
Could not find module ‘Control.Effect’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Control.Effect
| ^^^^^^^^^^^^^^^^^^^^^
Test suite doctestd: FAIL
Test suite logged to:
/Users/user/work/hstest9/dist-newstyle/build/x86_64-osx/ghc-8.8.1/hstest9-0.1.0.0/t/doctestd/test/hstest9-0.1.0.0-doctestd.log
0 of 1 test suites (0 of 1 test cases) passed.
cabal: Tests failed for test:doctestd from hstest9-0.1.0.0.
Your doctest doesn't find proper GHC_ENVIRONEMNT.
Since Cabal 3.0, cabal v2-build doesn't generate environment files by default.
Since Cabal 3.0, defaults to never. Before that, defaulted to creating them only when compiling with GHC 8.4.4 and older (GHC 8.4.4 is the first version that supports the -package-env - option that allows ignoring the package environment files).
https://www.haskell.org/cabal/users-guide/nix-local-build.html#cfg-field-write-ghc-environment-files
So you should set this option on v2-build.
$ cabal v2-build --write-ghc-environment-files=ghc8.4.4+
Or you can write this in $HOME/.cabal/config for default cabal behavior.
write-ghc-environment-files: ghc8.4.4+

Haskell there are files missing in the QuickCheck-2.11.3 package

I tried running my program which uses Haskell QuickCheck via ghc MyProgramm.hs , but received the following error:
$ ghc Ex2.hs
[1 of 1] Compiling Ex2 ( Ex2.hs, Ex2.o )
Ex2.hs:21:1: error:
Could not find module ‘Test.QuickCheck’
There are files missing in the ‘QuickCheck-2.11.3’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
21 | import Test.QuickCheck (
| ^^^^^^^^^^^^^^^^^^^^^^^^...
I installed stack, ran stack update and stack install QuickCheck without issue but the error persisted. Then, I ran cabal install QuickCheck and got the following errors:
$ cabal install QuickCheck
Resolving dependencies...
Configuring QuickCheck-2.12.4...
Building QuickCheck-2.12.4...
Failed to install QuickCheck-2.12.4
Build log ( /home/username/.cabal/logs/ghc-8.4.3/QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK.log ):
cabal: Entering directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
Configuring QuickCheck-2.12.4...
Preprocessing library for QuickCheck-2.12.4..
Building library for QuickCheck-2.12.4..
[ 1 of 16] Compiling Test.QuickCheck.Exception ( Test/QuickCheck/Exception.hs, dist/build/Test/QuickCheck/Exception.o )
[ 2 of 16] Compiling Test.QuickCheck.Random ( Test/QuickCheck/Random.hs, dist/build/Test/QuickCheck/Random.o )
Test/QuickCheck/Random.hs:10:1: error:
Could not find module ‘System.Random’
There are files missing in the ‘random-1.1’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
10 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:11:1: error:
Could not find module ‘System.Random.TF’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
11 | import System.Random.TF
| ^^^^^^^^^^^^^^^^^^^^^^^
Test/QuickCheck/Random.hs:12:1: error:
Could not find module ‘System.Random.TF.Gen’
There are files missing in the ‘tf-random-0.5’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
12 | import System.Random.TF.Gen(splitn)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Leaving directory '/tmp/cabal-tmp-9133/QuickCheck-2.12.4'
cabal: Error: some packages failed to install:
QuickCheck-2.12.4-3d2YDDqfPBn4BfmTJbpJXK failed during the building phase. The
exception was:
ExitFailure 1
However, I already have the arch packages haskell-random, haskell-tf-random and haskell-mwc-random installed. Does anybody know how to fix this?
Edit: I also ran cabal install random --reinstall.
Problem
On Archlinux as of 2022-09-17, pacman -S ghc cabal-install will install
system packages that provide only dynamic files (.so, .dyn_hi) in
installed packages inside /usr/lib/ghc-*; static files (.a, .hi) are (for
the most part) missing. However, the default cabal configuration enables static file
building. Unfortunately, upstream cabal-install doesn't track whether or not
static files are available inside installed packages. It just assumes they
are, and when they are gone, it fails with errors such as you have found:
[1 of 1] Compiling Main ( Main.hs, ../setup.dist/work/depender/dist/build/depender/depender-tmp/Main.o )
Main.hs:3:1: error:
Could not find module `Dynamic'
There are files missing in the `dynamic-1.0' package,
try running 'ghc-pkg check'.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
| import qualified Dynamic (number)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Workaround
A quick workaround just to get up and running quickly is to disable static file
building, which is by default enabled. (Note that trying to pass package-local
flags to disable static file with e.g. --enable-shared --enable-executable-dynamic --disable-library-vanilla (which is how most if
not all current Archlinux Haskell packages seem to build packages, e.g. with
https://github.com/archlinux/svntogit-community/blob/master/haskell-scientific/trunk/PKGBUILD)
building using cabal-install may be ignored due to another, related bug; but
~/.cabal/config is a safe bet.) You may do so by adding 3 lines to
~/.cabal/config in the appropriate location:
library-vanilla: False
shared: True
executable-dynamic: True
(Alternatively, consider using alternative tools like stack.)
More complete solution
For a more long-term solution, one option involves 2 pieces: 1) one or more
system packages that provide all types of build artifacts, static and dynamic,
for the base, foundational packages (from GHC and cabal-install), at least as an option besides dynamic-only packages (secondary Haskell packages are optional,
since cabal-install can rebuild these with needed build artifacts (static or
dynamic)), and 2) patching cabal-install (and ghc-pkg, which can handle .conf
files recording information about installed packages) to track whether static
files are available, and to be aware of these when resolving dependencies so
that cabal-install knows when to prefer rebuild a source package with needed
build artifact configuration over an already installed package that doesn't
provid required build artifacts.
There is a merge request (I submitted) that provides such a patchset, called
fix-dynamic-deps, at https://github.com/haskell/cabal/pull/8461. For users
running into exactly the problem that you described (myself included), I also
created an AUR package that provides both pieces based on GHC 9.4.2 with Cabal
3.9.0.0 that includes my patchset (there is a mirror at
https://github.com/bairyn/ghc-cabal-arts.) It provides ghc and
cabal-install but includes both of these pieces.
Further reading
Here are a few more resources I wrote on or are related to this bug:
https://wiki.archlinux.org/index.php?title=Haskell&diff=745459&oldid=738269#Troubleshooting
https://github.com/haskell/cabal/pull/8461
https://github.com/bairyn/ghc-cabal-arts
https://github.com/bairyn/cabal/tree/fix-dynamic-builds
Even though I have a main = do and couldn't get it working that way, I was able to run my QuickCheck test as follows:
To run a quickCheck, first load your program with:
$ ghci MyProg.hs
Then to run the quickCheck, find the test you want to run, then run it with:
$ quickCheck my_quick_check

haskell stack won't install dates

In a standalone module I'm using the dates package http://hackage.haskell.org/package/dates installed via cabal and it works fine. But a problem emerges when I try to make a small package out of this module using stack. The dates package is appropriately listed in dependencies and all but it doesn't work. When I try to manually install the package using stack in the project sandbox, I get the below error. Meanwhile I can install this package with cabal outside the stack sandbox without issues.
VERSIONS IN THE SANDBOX:
ghc-8.4.3
stack-1.7.1
SYSTEM VERSIONS:
ghc-8.0.2
cabal-1.24.0.2 (compiled 1.24.2.0)
error message:
Configuring dates-0.2.2.1...
Preprocessing library for dates-0.2.2.1..
Building library for dates-0.2.2.1..
[1 of 4] Compiling Data.Dates.Internal ( Data/Dates/Internal.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Data/Dates/Internal.o )
[2 of 4] Compiling Data.Dates.Types ( Data/Dates/Types.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Data/Dates/Types.o )
/tmp/stack16211/dates-0.2.2.1/Data/Dates/Types.hs:62:10: error:
• No instance for (Semigroup DateTime)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid DateTime’
|
62 | instance Monoid DateTime where
| ^^^^^^^^^^^^^^^
In the end I needed to change the resolver in the stack.yaml file to an older version (lts-8.24) which would enforce the use of ghc-8.0.2. Using
stack --resolver ghc-8.0.2 setup/build
did not prevent stack from using the latest ghc version when I did
stack exec blah-exe
which raised the conflict.

Resources