Stack build fails due to missing package although stack ghci works - 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 Yesod problems

someone could help me?! I'm working in a Haskell Yesod site for college on a C9 workspace, I've already installed by command Yesod and update cabal, but when I try "stack build" command, this miserable error message appears:
$ stack build
aulahaskell-0.0.0: build (lib + exe)
Preprocessing library aulahaskell-0.0.0...
[ 7 of 13] Compiling Handler.Cliente ( src/Handler/Cliente.hs, .stack-work/dist/x86_64-linux/Cabal-1.24.2.0/build/Handler/Cliente.o )
/home/ubuntu/workspace/web2017/src/Handler/Cliente.hs:10:1: error:
Failed to load interface for ‘Network.HTTP.Types.Status’
It is a member of the hidden package ‘http-types-0.9.1’.
Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
-- While building package aulahaskell-0.0.0 using:
/home/ubuntu/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.2.0 build lib:aulahaskell exe:aulahaskell --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Seriously, I tried a bunch of things to fix it, but nothing is working =S
Just read the error message carefully:
Failed to load interface for ‘Network.HTTP.Types.Status’
It is a member of the hidden package ‘http-types-0.9.1’.
Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
The line Perhaps you need to add ‘http-types’ to the build-depends in your .cabal file tells you what to do: You must add http-types to the build-depends: section of the library aulahaskell in your cabal file.
If this does not help, please post your cabal file.
How did you start the yesod project? It's recommended to do:
stack new my-yesod-project yesod-(your database here)
cd my-yesod-project
stack build
Thank you, guys! It was a problem on how I was starting the project, some files weren't installed on my workspace, so I delete the files, reinstall Yesod and cabal, create another new version after following this steps: https://www.yesodweb.com/page/quickstart

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.

cabal build missing Control.Monad.State even though mtl is in build-depends [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.

Resources