cabal build missing Control.Monad.State even though mtl is in build-depends [duplicate] - haskell

I am trying to build a simple program in Haskell using stack. I created a new project using stack new and did a stack setup after that. The template builds fine.
I want to experiment with binary file parsing, so I imported Data.ByteString. My build-depends in the cabal file look like this:
build-depends: base >= 4.7 && < 5
, bytestring >= 0.10.6
, binary >= 0.7.5
stack ghci now just works, but stack build is still not happy.
Can someone tell me what I did wrong here?
Here is the complete error message:
test-0.1.0.0: build
Preprocessing library test-0.1.0.0...
In-place registering test-0.1.0.0...
Preprocessing executable 'test-exe' for test-0.1.0.0...
haskell/test/app/Main.hs:4:18:
Could not find module ‘Data.ByteString’
It is a member of the hidden package ‘bytestring-0.10.6.0#bytes_6VWy06pWzJq9evDvK2d4w6’.
Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
haskell/test/app/Main.hs:5:8:
Could not find module ‘Data.Binary.Get’
It is a member of the hidden package ‘binary-0.7.5.0#binar_3uXFWMoAGBg0xKP9MHKRwi’.
Perhaps you need to add ‘binary’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package test-0.1.0.0 using:
.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:test exe:test-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
and this is my app/Main.hs file:
module Main where
import Lib
import qualified Data.ByteString as B
import Data.Binary.Get
import Data.Word
main :: IO ()
main = do
putStrLn "f"
Thank you very much for your help.

This is likely because you added bytestring to the build-depends of the library, not the executable. One option to avoid needing to repeat these dependencies for the different stanzas is to use hpack as the package description format.

Related

haskell fail to import Data.List module

|
4 | import Data.List.Split
| ^^^^^^^^^^^^^^^^^^^^^^
-- While building package myproj-0.1.0.0 using:
Process exited with code: ExitFailure 1
I got this error, how can i import the module to haskell file?
I got this error when compile in vs code or when debugging
Second error in file after compile with stack build, i already added Split in cabal build depends
Cabal file
Building all executables for `myproj' once. After a successful build of all of them, only specified executables will be rebuilt.
myproj> configure (exe)
Warning: myproj.cabal:21:10: Tabs used as indentation at 21:10
Configuring myproj-0.1.0.0...
myproj> build (exe)
Preprocessing executable 'myproj' for myproj-0.1.0.0..
Building executable 'myproj' for myproj-0.1.0.0..
<no location info>: error:
output was redirected with -o, but no output will be generated
because there is no Main module.
First you need to find out in which package the module is included.
https://hoogle.haskell.org/?hoogle=Data.List.Split
So you need the split package. Put in the build-depends of your myproj.cabal file (or package.yaml, if you use hpack or stack)
split >=0.2 && <0.3
(the version bounds are optional, but it's recommended to fix the x.y when in doubt)
Then, at next build, cabal or stack will pull in the required dependencies and thus make the module available.

Text/Regex/TDFA/NewDFA/Engine.hs:13:33: parse error on input ‘#’

I have been trying to run a simple Haskell program using TDFA. The program is as follows:
import Control.Monad
import Data.Array
import qualified Data.Text as T
import Text.Regex
import Text.Regex.TDFA
import Text.Regex.Base
str = "abbbbaab" :: String
regex = "(a+)(b+)" :: String
main = do
if str (=~) :: regex then putStrLn "matched" else putStrLn "no matches"
when I try to run the above program using the command like: ghc test.hs -o test and then I am getting the following error (test.hs is the Haskell program which contains the above code):
Text/Regex/TDFA/NewDFA/Engine.hs:13:33: parse error on input ‘#’
Note that I have the latest version of TDFA installed on my pc. I did it by following ways:
ghc --make -o setup Setup.hs
Also, I did the following:
user#user-VirtualBox:~/regex-tdfa-master$ sudo cabal install regex-tdfa
[sudo] password for user:
Resolving dependencies...
All the requested packages are already installed:
regex-tdfa-1.2.2
Use --reinstall if you want to reinstall anyway.
I even tried it with the Makefile which I got from TDFA's github repository:
user#user-VirtualBox:~/regex-tdfa-master$ make
ghc -o setup --make ./Setup.hs
./setup clean
cleaning...
./setup configure --prefix=/Users/user/local/devel/trl --enable-library-profiling --user
Configuring regex-tdfa-1.2.2...
./setup build
Building regex-tdfa-1.2.2...
Preprocessing` library regex-tdfa-1.2.2...
[ 1 of 23] Compiling Text.Regex.TDFA.NewDFA.Uncons ( Text/Regex/TDFA/NewDFA/Uncons.hs, dist/build/Text/Regex/TDFA/NewDFA/Uncons.o )
...........(Skipped to make the things short here)..............................
[23 of 23] Compiling Text.Regex.TDFA ( Text/Regex/TDFA.hs, dist/build/Text/Regex/TDFA.o )
Text/Regex/TDFA.hs:60:8:
Could not find module ‘Text.Regex.Base’
Perhaps you haven't installed the profiling libraries for package ‘regex-base-0.93.2#regex_47KXx9dLqeO8MNJeizLKhP’?
Use -v to see a list of the files searched for.
Text/Regex/TDFA/ByteString.hs:24:8:
Could not find module ‘Text.Regex.Base.Impl’
Perhaps you haven't installed the profiling libraries for package ‘regex-base-0.93.2#regex_47KXx9dLqeO8MNJeizLKhP’?
Use -v to see a list of the files searched for.
Text/Regex/TDFA/CorePattern.hs:37:8:
Could not find module ‘Control.Monad.RWS’
Perhaps you haven't installed the profiling libraries for package ‘mtl-2.2.1#mtl_Aue4leSeVkpKLsfHIV51E8’?
Use -v to see a list of the files searched for.
Text/Regex/TDFA/ReadRegex.hs:13:8:
`Could not find module ‘Text.ParserCombinators.Parsec’`
Perhaps you haven't installed the profiling libraries for package ‘parsec-3.1.9#parse_EE5NO1mlYLh4J8mgDEshNv’?
Use -v to see a list of the files searched for.
Text/Regex/TDFA/String.hs:23:8:
Could not find module ‘Text.Regex.Base.RegexLike’`
Perhaps you haven't installed the profiling libraries for package ‘regex-base-0.93.2#regex_47KXx9dLqeO8MNJeizLKhP’?
Use -v to see a list of the files searched for.
Text/Regex/TDFA/TDFA.hs:10:8:`
Could not find module ‘Control.Monad.State’
Perhaps you haven't installed the profiling libraries for package ‘mtl-2.2.1#mtl_Aue4leSeVkpKLsfHIV51E8’?
Use -v to see a list of the files searched for.
Makefile:16: recipe for target 'build' failed
make: *** [build] Error 1
user#user-VirtualBox:~/regex-tdfa-master$
However, nothing worked. Hence, any help would be so appreciated...
Text/Regex/TDFA/NewDFA/Engine.hs:13:33: parse error on input ‘#’
On an initial note, this error points to a module of the regex-tdfa package, so you should have gotten it when building the package, rather than when building your test.hs, unless you were trying to build test.hs after putting it within the package source tree. In any case, line 13 of the mentioned file is:
import GHC.Prim(MutableByteArray#,RealWorld,Int#,sizeofMutableByteArray#,unsafeCoerce#)
The # names require the MagicHash GHC extension to be enabled. As there is no {-# LANGUAGE MagicHash #-} pragma at the beginning of the file, one should assume the extension is enabled through the .cabal file of the package, and that is indeed the case. That being so, your problem seems to be that you are attempting use the package modules straight from the source tree, without using an appropriate build tool such as Cabal. (Note that if you did successfully run cabal install regex-tdfa there should be no need of dealing with the source tree: ghc --make -o test test.hs should be enough.)
P.S.: There is an error in your test.hs. The last line should be...
if str =~ regex then putStrLn "matched" else putStrLn "no matches"
(I did manage to run it after this correction.)
It looks like you are compiling your program from within Regex-TDFA source code. I am able to reproduce your problem if I do cabal unpack regex-tdfa && cd regex-tdfa-1.2.2 && ghc --make test.hs.
The error happens because when GHC finds Regex-TDFA source files in the current directory, it just picks them and tries to compile, as if they were ordinary source files belonging to your project. However, Regex-TDFA cannot be built with simple ghc --make: in order to build it, you have to run cabal first. Cabal will read regex-tdfa.cabal file that contains the list of the necessary GHC extensions.
In particular, parse error happens because GHC extension MagicHash is missing (that's where the hash # comes from).
The "fix" is to move your test.hs to some other location: then GHC will use system package for Regex-TDFA.

haskell stack - random numbers package [duplicate]

I am trying to build a simple program in Haskell using stack. I created a new project using stack new and did a stack setup after that. The template builds fine.
I want to experiment with binary file parsing, so I imported Data.ByteString. My build-depends in the cabal file look like this:
build-depends: base >= 4.7 && < 5
, bytestring >= 0.10.6
, binary >= 0.7.5
stack ghci now just works, but stack build is still not happy.
Can someone tell me what I did wrong here?
Here is the complete error message:
test-0.1.0.0: build
Preprocessing library test-0.1.0.0...
In-place registering test-0.1.0.0...
Preprocessing executable 'test-exe' for test-0.1.0.0...
haskell/test/app/Main.hs:4:18:
Could not find module ‘Data.ByteString’
It is a member of the hidden package ‘bytestring-0.10.6.0#bytes_6VWy06pWzJq9evDvK2d4w6’.
Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
haskell/test/app/Main.hs:5:8:
Could not find module ‘Data.Binary.Get’
It is a member of the hidden package ‘binary-0.7.5.0#binar_3uXFWMoAGBg0xKP9MHKRwi’.
Perhaps you need to add ‘binary’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package test-0.1.0.0 using:
.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:test exe:test-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
and this is my app/Main.hs file:
module Main where
import Lib
import qualified Data.ByteString as B
import Data.Binary.Get
import Data.Word
main :: IO ()
main = do
putStrLn "f"
Thank you very much for your help.
This is likely because you added bytestring to the build-depends of the library, not the executable. One option to avoid needing to repeat these dependencies for the different stanzas is to use hpack as the package description format.

How do I add the "containers" package to my .cabal file (without getting overwritten by stack at compile time)?

I am working on the "roman-numerals" task from the exercism Haskell track and followed their instructions to installing stack. I am working on a Fedora 24 box.
As long as I was working with Haskell modules from base, I didn't have a problem. Now I am trying to import the Data.Map module. It works fine using the ghci command line:
$ ghci
GHCi, version 7.8.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Data.Map
Prelude Data.Map>
However, when I try to import it from inside my src file with the command:
import qualified Data.Map as M (foldlWithKey, fromList)
I am running into problems when I try to run the test:
$ stack test
roman-numerals-0.0.0: build (lib + test)
Preprocessing library roman-numerals-0.0.0...
[2 of 2] Compiling Roman (...)
(...) /roman-numerals/src/Roman.hs:3:1: error:
Failed to load interface for ‘Data.Map’
It is a member of the hidden package ‘containers-0.5.7.1’.
Perhaps you need to add ‘containers’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
Progress: 1/2
(...)
I googled the problem and found a straightforward solution at the Cabal FAQ at haskell.org:
What you need to do is to add containers to the build-depends in your .cabal file.
I am assuming they mean the file roman-numerals.cabal that is in my working directory. The contents are:
-- This file has been generated from package.yaml by hpack version 0.14.0.
--
-- see: https://github.com/sol/hpack
name: roman-numerals
version: 0.0.0
build-type: Simple
cabal-version: >= 1.10
library
hs-source-dirs:
src
build-depends:
base
exposed-modules:
Roman
other-modules:
Paths_roman_numerals
default-language: Haskell2010
test-suite test
type: exitcode-stdio-1.0
main-is: Tests.hs
hs-source-dirs:
test
build-depends:
base
, roman-numerals
, hspec
default-language: Haskell2010
I tried to add "containers" to the build-depends in either and both the "library" and "test-suite" sections, but when I run
$ stack test
the error persists, and the .cabal file is reverted to the same contents shown above.
Any pointers? Much appreciated!
This is hinting at the problem:
-- This file has been generated from package.yaml by hpack version 0.14.0.
--
-- see: https://github.com/sol/hpack
hpack is an alternative, YAML-based specification format for Haskell packages which can be used instead of the traditional cabal format. The hpack program can then be used to convert a specification from the hpack format to the cabal format to be able to integrate with the rest of the Haskell toolchain.
Some basic support for hpack was added to stack some time ago. It checks for a file called package.yaml in the current directory, which is the standard name for hpack format package specifications, and if it exists, it runs hpack to convert it to a cabal file and then proceeds building as normal. This is what's trampling over your .cabal file.
To solve this, either:
Modify package.yaml instead of roman-numerals.cabal to achieve the same effect.
Delete package.yaml and continue working directly with roman-numerals.cabal.
The syntax for adding dependencies in the hpack format is:
dependencies:
- base
- containers

Stack build fails due to missing package although stack ghci works

I am trying to build a simple program in Haskell using stack. I created a new project using stack new and did a stack setup after that. The template builds fine.
I want to experiment with binary file parsing, so I imported Data.ByteString. My build-depends in the cabal file look like this:
build-depends: base >= 4.7 && < 5
, bytestring >= 0.10.6
, binary >= 0.7.5
stack ghci now just works, but stack build is still not happy.
Can someone tell me what I did wrong here?
Here is the complete error message:
test-0.1.0.0: build
Preprocessing library test-0.1.0.0...
In-place registering test-0.1.0.0...
Preprocessing executable 'test-exe' for test-0.1.0.0...
haskell/test/app/Main.hs:4:18:
Could not find module ‘Data.ByteString’
It is a member of the hidden package ‘bytestring-0.10.6.0#bytes_6VWy06pWzJq9evDvK2d4w6’.
Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
haskell/test/app/Main.hs:5:8:
Could not find module ‘Data.Binary.Get’
It is a member of the hidden package ‘binary-0.7.5.0#binar_3uXFWMoAGBg0xKP9MHKRwi’.
Perhaps you need to add ‘binary’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package test-0.1.0.0 using:
.stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:test exe:test-exe --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
and this is my app/Main.hs file:
module Main where
import Lib
import qualified Data.ByteString as B
import Data.Binary.Get
import Data.Word
main :: IO ()
main = do
putStrLn "f"
Thank you very much for your help.
This is likely because you added bytestring to the build-depends of the library, not the executable. One option to avoid needing to repeat these dependencies for the different stanzas is to use hpack as the package description format.

Resources