Problem loading module Data.Number.CReal in cabal file - haskell

I installed a simple proyect with stack, my stack.yaml looks like:
resolver: lts-14.6
packages:
- .
dependencies:
- base (>=3 && <5)
- numbers
and I have a simple code that only calls a function:
module Main where
import Lib
import Data.Number.CReal
main :: IO ()
main = someFunc
and the error is always the same:
numbers-play-0.1.0.0: unregistering (local file changes: numbers-play.cabal)
numbers-play> configure (lib + exe)
Configuring numbers-play-0.1.0.0...
numbers-play> build (lib + exe)
Preprocessing library for numbers-play-0.1.0.0..
Building library for numbers-play-0.1.0.0..
[1 of 2] Compiling Lib
[2 of 2] Compiling Paths_numbers_play
Preprocessing executable 'numbers-play-exe' for numbers-play-0.1.0.0..
Building executable 'numbers-play-exe' for numbers-play-0.1.0.0..
[1 of 2] Compiling Main [Data.Number.CReal changed]
/home/damian/dev/haskell/numbers-play/app/Main.hs:4:1: error:
Could not load module ‘Data.Number.CReal’
It is a member of the hidden package ‘numbers-3000.2.0.2’.
Perhaps you need to add ‘numbers’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
|
4 | import Data.Number.CReal
| ^^^^^^^^^^^^^^^^^^^^^^^^
My cabal file:
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: fb0ed9e8eb8062639f1d6a02a65d857d15b3265158925242287d4a8a885f8381
name: numbers-play
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/numbers-play#readme>
homepage: https://github.com/githubuser/numbers-play#readme
bug-reports: https://github.com/githubuser/numbers-play/issues
author: Author name here
maintainer: example#example.com
copyright: 2019 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/githubuser/numbers-play
library
exposed-modules:
Lib
other-modules:
Paths_numbers_play
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
default-language: Haskell2010
executable numbers-play-exe
main-is: Main.hs
other-modules:
Paths_numbers_play
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, numbers-play
default-language: Haskell2010
test-suite numbers-play-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_numbers_play
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, numbers-play
default-language: Haskell2010
How can I import it properly?

The dependencies field, which specifies the numbers dependency, should be in your package.yaml file (which Stack uses to generate the cabal file), and not in stack.yaml (which is for Stack-specific configuration, such as choosing the resolver).

Related

stack setup won't recognize changes in .cabal file

I've added "QuickCheck" to the "build depends" section of the .cabal file but when I do stack setup the "QuickCheck" section of the file gets removed and I get this error:
It is a member of the hidden package ‘Cabal-3.2.1.0’.
You can run ‘:set -package Cabal’ 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.
|
1 | import Distribution.Simple
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
the stack build and stack ghci work fine but stack test gives this error:
Could not find module ‘Test.QuickCheck’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
3 | import Test.QuickCheck
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Progress 1/2
-- While building package palindrome-testing-0.1.0.0 (scroll up to its section to see the error) using:
/Users/artin/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.2.1.0 build lib:palindrome-testing exe:palindrome-testing-exe test:palindrome-testing-test --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
.cabal file:
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.34.6.
--
-- see: https://github.com/sol/hpack
name: palindrome-testing
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/githubuser/palindrome-testing#readme>
homepage: https://github.com/githubuser/palindrome-testing#readme
bug-reports: https://github.com/githubuser/palindrome-testing/issues
author: Author name here
maintainer: example#example.com
copyright: 2022 Author name here
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
source-repository head
type: git
location: https://github.com/githubuser/palindrome-testing
library
exposed-modules:
Lib
other-modules:
Paths_palindrome_testing
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
default-language: Haskell2010
executable palindrome-testing-exe
main-is: Main.hs
other-modules:
Paths_palindrome_testing
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, palindrome-testing
default-language: Haskell2010
test-suite palindrome-testing-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_palindrome_testing
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, palindrome-testing
, QuickCheck
default-language: Haskell2010
ghc version: 8.10.7
stack version: 2.7.4
cabal version: 3.6.2
I'm running macOS monterey on M1
Your cabal file was generated from the package.yaml file in that directory:
-- This file has been generated from package.yaml by hpack version 0.34.6.
--
-- see: https://github.com/sol/hpack
If you want to add new dependencies, add them to package.yaml. Any changes you make to the .cabal file will get overridden.

Stack auto-removes dependency from .cabal file following 'stack build'

I want to work on a new Haskell project using the threepenny-gui package.
The first thing I did was create a stack project via $ stack new threepennydemo. From here, here, I did the following:
I edited the extra-deps section in my stack.yaml file from:
# extra-deps: []
to
extra-deps:
- threepenny-gui-0.9.0.0
I edited the .cabal file from:
library
exposed-modules:
Lib
other-modules:
Paths_threepennydemo
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
default-language: Haskell2010
executable threepennydemo-exe
main-is: Main.hs
other-modules:
Paths_threepennydemo
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, threepennydemo
default-language: Haskell2010
test-suite threepennydemo-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_threepennydemo
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, threepennydemo
default-language: Haskell2010
to
library
exposed-modules:
Lib
other-modules:
Paths_threepennydemo
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, threepenny-gui >= 0.9
default-language: Haskell2010
executable threepennydemo-exe
main-is: Main.hs
other-modules:
Paths_threepennydemo
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, threepennydemo
, threepenny-gui >= 0.9
default-language: Haskell2010
test-suite threepennydemo-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_threepennydemo
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, threepennydemo
, threepenny-gui >= 0.9
default-language: Haskell2010
I edited the stock /app/Main.hs from:
module Main where
import Lib
main :: IO ()
main = someFunc
to
import Graphics.UI.Threepenny
main :: IO ()
main = do
startGUI defaultConfig showMessage
showMessage :: Window -> UI ()
showMessage window = do
getBody window #+ [string "Hello, world!"]
return ()
I enter the command $ stack build.
From here, I notice two things. The first is that I receive the following error:
Building all executables for `threepennydemo' once. After a successful build of all of them, only specified executables will be rebuilt.
threepennydemo> configure (lib + exe)
Configuring threepennydemo-0.1.0.0...
threepennydemo> build (lib + exe)
Preprocessing library for threepennydemo-0.1.0.0..
Building library for threepennydemo-0.1.0.0..
Preprocessing executable 'threepennydemo-exe' for threepennydemo-0.1.0.0..
Building executable 'threepennydemo-exe' for threepennydemo-0.1.0.0..
[1 of 2] Compiling Main
/Users/my_username/threepennydemo/app/Main.hs:1:1: error:
Could not load module ‘Graphics.UI.Threepenny’
It is a member of the hidden package ‘threepenny-gui-0.9.0.0’.
Perhaps you need to add ‘threepenny-gui’ to the build-depends in your .cabal file.
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
|
1 | import Graphics.UI.Threepenny
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- While building package threepennydemo-0.1.0.0 using:
/Users/my_username/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4 --builddir=.stack-work/dist/x86_64-osx/Cabal-3.0.1.0 build lib:threepennydemo exe:threepennydemo-exe --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
The second is that my .cabal file, edited as mentioned in 2., has automatically removed the edits I made to the file.
What am I missing in order to be able to use a third party library when setting up a new stack project?
My difficulty as the result of some confusion between stack.yaml and package.yaml. The latter being what generates the threepennydemo.cabal file. Hence, dependencies must also be specified to a package.yaml file. Adding this dependency to the package.yaml allowed $ stack build to complete without issue.

How to add dependencies and make it visible to Intero in Haskell

I want to use System.Directory in emacs with Haskell mode and Intero, While the on the fly check warns that Couldn't find module System.Directory. So I add some dependencies in my cabal file. And the warning doesn't disappear while the stack build successfully executed.
Below is my cabal file:
-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 536b5f6ecaaec7d4b7a9694c8f69bbe648a1d21d80fa721e533ac5b139955401
name: find
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/Handora/find#readme>
homepage: https://github.com/Handora/find#readme
bug-reports: https://github.com/Handora/find/issues
author: Handora
maintainer: qcdsr970209#gmail.com
copyright: Qian Chen
license: BSD3
license-file: LICENSE
build-type: Simple
cabal-version: >= 1.10
extra-source-files:
ChangeLog.md
README.md
source-repository head
type: git
location: https://github.com/Handora/find
library
exposed-modules:
Lib
RecursiveContents
other-modules:
Paths_find
hs-source-dirs:
src
build-depends:
base >=4.7 && <5
, directory
default-language: Haskell2010
executable find-exe
main-is: Main.hs
other-modules:
Paths_find
hs-source-dirs:
app
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, find
, directory
default-language: Haskell2010
test-suite find-test
type: exitcode-stdio-1.0
main-is: Spec.hs
other-modules:
Paths_find
hs-source-dirs:
test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, find
default-language: Haskell2010
I add the directory into build dependencies and executable build dependencies. So my question is how to make the System.Directory visible to Intero, so the warnings can disappear.
You can get it to show up by running intero-restart.
There may be a "more correct" way, but this works.

Stack fails to build

I am trying to learn haskell here (don't ask why), and I am starting with a very simple code, that i even copied from github.
So the code is this:
module Example () where
import Network.HTTP
-- Non HTTPS
-- 1. Perform a basic HTTP get request and return the body
get :: String -> IO String
get url = simpleHTTP (getRequest url) >>= getResponseBody
-- 2. Get the response code
getCode :: String -> IO ResponseCode
getCode url = simpleHTTP req >>= getResponseCode
where req = getRequest url
However, when I run stack build I get this:
slack-client-0.1.0.0: build
Preprocessing library slack-client-0.1.0.0...
[2 of 2] Compiling Example ( src\Example.hs, .stack-work\dist\b7fec021\
build\Example.o )
D:\haskell\slack-client\src\Example.hs:3:1: error:
Failed to load interface for `Network.HTTP'
It is a member of the hidden package `HTTP-4000.3.3'.
Perhaps you need to add `HTTP' to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package slack-client-0.1.0.0 using:
C:\Users\Mihai\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\setup-
Simple-Cabal-1.24.0.0-ghc-8.0.1.exe --builddir=.stack-work\dist\b7fec021 build l
ib:slack-client exe:slack-client-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
This is my .cabal file:
name: slack-client
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: https://github.com/githubuser/slack-client#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example#example.com
copyright: 2016 Author name here
category: Web
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
other-modules: Example
build-depends: base >= 4.7 && < 5
default-language: Haskell2010
executable slack-client-exe
hs-source-dirs: app
main-is: Main.hs
other-modules: Example
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, HTTP
, HTTP-Simple
, slack-client
default-language: Haskell2010
test-suite slack-client-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, HTTP-Simple
, slack-client
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
source-repository head
type: git
location: https://github.com/githubuser/slack-client
What am i doing wrong?
If you want your `Example module to be a part of executable, add to this section
executable slack-client-exe
hs-source-dirs: app
main-is: Main.hs
this line: other-modules: Example.
If you want it to be a part of the library, change
library
hs-source-dirs: src
exposed-modules: Lib
to
library
hs-source-dirs: src
exposed-modules: Lib, Example
And take a look at cabal documentation.

Cabal reporting it can't find module

I have configured the following cabal file but when I do cabal build I just get the error in file Tasty.hs saying Could not find module TicTac.Essential, what am I missing here?
name: tdd
version: 0.1.0.0
cabal-version: >=1.8
-- synopsis:
-- description:
-- license:
license-file: LICENSE
author: adfaf
maintainer: info#adfadsf.se
-- copyright:
-- category:
build-type: Simple
extra-source-files: README
library
hs-source-dirs: src
build-depends: base >= 4
ghc-options: -Wall
exposed-modules TicTac.Essential
default-language: Haskell2010
test-suite Tasty
type: exitcode-stdio-1.0
build-depends: base >=4.6 && <4.7, tasty, tasty-quickcheck, tdd
hs-source-dirs: test
main-is: Tasty.hs
Source of tasty.hs
module Main where
import Test.Tasty
import Test.Tasty.QuickCheck as QC
import TicTac.Essential
You're missing a colon after "exposed-modules". Should be
library
hs-source-dirs: src
build-depends: base >= 4
ghc-options: -Wall
exposed-modules: TicTac.Essential
default-language: Haskell2010

Resources