I'm trying to compile some code in Real World Haskell - Chapter 24. LineCount.hs.
I have not made any changes to the code.
However, when I do:
ghc -O2 --make -threaded LineCount.hs
(as instructed in the book), I get the message:
MapReduce.hs:6:7: Not in scope: `rnf'
What might I be doing wrong?
A quick search showed up that there was some trouble with the packages parallel and strict-concurrency in the past, and that reinstalling them would fix the issue. However, I tried that and it didn't work. Moreover, it is noted there that that issue was fixed sometime in 2010:
https://groups.google.com/forum/?fromgroups=#!msg/happs/gOieP4xfpNc/nrasm842JlUJ
Note: I get various other errors when compiling other files in the same chapter. For example, on compiling Strat.hs I get: Module Control.Parallel.Strategies' does not exportparZipWith'. On compiling LineChunks.hs I get: Module Control.Parallel.Strategies' does not exportrnf'.
Honestly, as a novice Haskell programmer I expected to run into trouble once I started modifying code - but I didn't expect to have trouble with code from a book!
The function is no longer called rnf. It's called rdeepseq now. Just replace it. :)
You can find the contents of the parallel package online by googling "control parallel strategies hackage", or clicking here.
Related
I was learning Haxe. And I found that a code that is in the official manual doesn't be compiled in https://try.haxe.org/. and I wonder why and how to fix the code?
the code is the one in here: https://haxe.org/manual/types-enum-using.html
try.haxe.org assumes that the class that contains the entry point main() is called Test, while the code example you linked uses Main.
It appears to work fine once you change class Main to class Test in the code snippet: https://try.haxe.org/#68274
Note that some other code examples from the manual may not compile because try.haxe.org still runs Haxe 3.4.4, while the current release is 4.0.5. To work around this, people usually use this fork of try.haxe that lets you specify the Haxe version to use in the options tab:
http://try-haxe.mrcdk.com/
My question comes in two parts. The first is that when I compile my project I get a long list of errors of the form
(.text+0x137f): undefined reference to `raytrzuAd6RComi0WmBiuT4685WWH_Types_zdfBinaryColor_closure'
The full list of errors can be found here
The code that produces this error can be found here.
I am using ghc 7.10.1 and cabal 1.22.4.0.
The second part of my question is that despite following the same cabal structure as this question, cabal still recompiles the library 3 times each cabal build despite the executables and the library all having a unique hs-source-dir and depending on the library.
EDIT: as far as the triple compilation is concerned, the first time it builds .o files [ 2 of 15] Compiling Types ( src/Types.hs, dist/build/Types.o ). The second time it builds .p_o files [ 2 of 15] Compiling Types ( src/Types.hs, dist/build/Types.p_o ) which are caused by TemplateHaskell and profiling.
You should include all the other non-exported modules in your Cabal file in the other-modules field, otherwise they won't be linked in properly when producing the final library or executable.
You can see the Cabal User's Guide for more information (although that pretty much sums up the situation with other-modules!).
I'm getting the following error when trying to install the contravariant library (which is needed for lens) with Cabal:
``src/Data/Functor/Contravariant.hs:96:1:
StateVar-1.1.0.0:Data.StateVar can't be safely imported! The module itself isn't safe.''
I've not had any success googling solutions, and tried a few fixes (such as getting rid of all my Haskell packages (with ``rm -r ~/.ghc'') and starting again), but I'm not really clear on what's causing this error to occur. I'm using ghc 7.4.1 - could that be the problem?
Thanks,
Reuben
Posting the correct answer from comments as community-wiki:
Looks like you're being hit by interactions between an old GHC and the
lack of Safe Haskell annotations (in the library) that are redundant
with newer GHC versions. Cf. http://github.com/ekmett/ersatz/issues/13
I recently made a cabal package which can be seen here
It consists of a library and a few small example programs using it. Everything builds and works as expected.
I wanted to build an executable in a new package which uses this library, however I continue to run into a linking error I can't decipher:
/my/path/RandomAgent/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.4/rlglue-0.2.1.1/libHSrlglue-0.2.1.1.a(Agent.o):(.text+0x34f1): undefined reference to `rlgluezm0zi2zi1zi1_Pathszurlglue_version1_closure'
collect2: error: ld returned 1 exit status
To make things simpler to diagnose I moved one of the examples programs into my new package and discovered even it won't build properly. You can find that version of the executable here.
From this I've concluded that the problem is likely in something I'm doing in my .cabal files, but I can't see what's wrong. The error also seems to refer to the Paths_rlglue module which cabal automatically generates for the first package.
Can anyone help me understand why I'm getting this error?
You need to include the Paths_rlglue module in exposed-modules or other-modules like any other module in your project so that Cabal will link it.
Cabal should be better about telling you what is going on, see https://github.com/haskell/cabal/issues/1746.
Looks like I missed something in the documentation for Paths_pkgname
If you decide to import the Paths_pkgname module then it must be
listed in the other-modules field just like any other module in your
package.
Adding Paths_rlglue to my library's other-modules fixed the issue. Hope this saves someone all the time I lost on this.
I would like to start using Haddock; the primary reason is not that I do (or anyone else does) need nice HTML documentation for what I'm writing right now, but that it will teach me a standardized way commenting Haskell modules.
For this reason, I'd like to get my hands dirty with it, but I've run into a pretty basic problem.
Source:
module Main where
-- |This is the main function.
main = putStrLn "Hello World!"
Haddock invocation:
> haddock -h test.hs
Haddock coverage:
50% ( 1 / 2) in 'Main'
Warning: Main: could not find link destinations for:
GHC.Types.IO
It looks like Haddock doesn't know where to look for the standard libraries, but that's just a wild guess. The docs say something about a "-B" parameter, but are not really explaining much about it.
I've searched for the problem online, and it was basically answered with "use a Cabal package and it'll do everything for you". However, I would much rather not deal with Cabal right now, but learn Haddock on its own (Cabal can wait). Is there a nice and easy(ish) solution to the problem?
I'm going to echo the wisdom of the comments to your question and say, just use Cabal. It's not an extra thing to learn, it's something to learn instead precisely because it takes care of all these tedious details for you. You'll probably need to know about it anyway since everyone else uses it, so you might as well get the benefit of that knowledge.
For completeness, I ran cabal haddock -v on one of my projects, and this is the invocation of haddock that it used:
/usr/local/bin/haddock --prologue=dist/doc/html/notcpp/haddock-prolog1566.txt --dump-interface=dist/doc/html/notcpp/notcpp.haddock --optghc=-package-name --optghc=notcpp-0.2.0.2 --hide=NotCPP.Utils --verbosity=1 --html --read-interface=/usr/local/share/doc/ghc/html/libraries/array-0.4.0.1,/usr/local/share/doc/ghc/html/libraries/array-0.4.0.1/array.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0,/usr/local/share/doc/ghc/html/libraries/base-4.6.0.0/base.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/containers-0.5.0.0,/usr/local/share/doc/ghc/html/libraries/containers-0.5.0.0/containers.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/deepseq-1.3.0.1,/usr/local/share/doc/ghc/html/libraries/deepseq-1.3.0.1/deepseq.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/ghc-prim-0.3.0.0,/usr/local/share/doc/ghc/html/libraries/ghc-prim-0.3.0.0/ghc-prim.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/integer-gmp-0.5.0.0,/usr/local/share/doc/ghc/html/libraries/integer-gmp-0.5.0.0/integer-gmp.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/pretty-1.1.1.0,/usr/local/share/doc/ghc/html/libraries/pretty-1.1.1.0/pretty.haddock --read-interface=/usr/local/share/doc/ghc/html/libraries/template-haskell-2.8.0.0,/usr/local/share/doc/ghc/html/libraries/template-haskell-2.8.0.0/template-haskell.haddock --odir=dist/doc/html/notcpp/ --title=notcpp-0.2.0.2: Avoiding the C preprocessor via cunning use of Template Haskell --optghc=-fbuilding-cabal-package --optghc=-O --optghc=-odir --optghc=dist/build/tmp-1566 --optghc=-hidir --optghc=dist/build/tmp-1566 --optghc=-stubdir --optghc=dist/build/tmp-1566 --optghc=-i --optghc=-idist/build --optghc=-i. --optghc=-idist/build/autogen --optghc=-Idist/build/autogen --optghc=-Idist/build --optghc=-optP-include --optghc=-optPdist/build/autogen/cabal_macros.h --optghc=-hide-all-packages --optghc=-package-id --optghc=base-4.6.0.0-eac4fa0d0988628e5bd960fef8805b26 --optghc=-package-id --optghc=template-haskell-2.8.0.0-102a52a4fda28374255d0a3a8e99f26c --optghc=-XHaskell98 --optghc=-XTemplateHaskell --optghc=-W -B/usr/local/lib/ghc-7.6.1 dist/build/tmp-1566/NotCPP/ScopeLookup.hs dist/build/tmp-1566/NotCPP/LookupValueName.hs dist/build/tmp-1566/NotCPP/OrphanEvasion.hs dist/build/tmp-1566/NotCPP/Utils.hs
Now, I'm sure much of that is optional, but I'm not about to spend the time working out which bits are and which aren't.