Bytestring can't be used - haskell

I created some code in the past which use Data.Bytestring.Lazy. Now, when I try to compile it, everithing what I get is a bunch of errors. Example of error:
Couldn't match expected type `BL.ByteString'
with actual type `bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString'
In the return type of a call of `decompress'
In the second argument of `decrypt', namely `(decompress fc)'
In the second argument of `BL.filter', namely
`(decrypt (extractKey tkey) (decompress fc))'
... And many errors like this ...
My import of bytestring: import Data.ByteString.Lazy as BL.
What to do with this?
EDIT:
THANKS for help. With explicit package version, everything works fine. But, I don't like this solution. When I try to unregister one of the two installed bytestring packages. Many packages will be broken. The newest package version break small amount of packages (no core packages). How to repair packeges which are destroyed by unregistering package?
EDIT:
No, it's not working fine with explicit package version. I wrote edit before I tried it physically. It was mistake. Nothing works.

Yes, I have solved the problem. The evil package was zlib which uses old version of bytestring, but all packages for encryption uses the new version. When I threw away code for compression, my program compiled. Now, I'm looking for some compression algorithms...

Related

How to render diagrams in gi-gtk?

I want to render a diagram on top of a GUI written with gi-gtk. I tryed to use the defaultRender function from the Diagrams.Backend.Gtk but the compiler is complaining with :
• Couldn't match expected type ‘gtk-0.15.5:Graphics.UI.Gtk.Types.DrawingArea’
with actual type ‘Gtk.DrawingArea’
NB: ‘Gtk.DrawingArea’
is defined in ‘GI.Gtk.Objects.DrawingArea’
in package ‘gi-gtk-3.0.36’
‘gtk-0.15.5:Graphics.UI.Gtk.Types.DrawingArea’
is defined in ‘Graphics.UI.Gtk.Types’ in package ‘gtk-0.15.5’
• In the first argument of ‘defaultRender’, namely ‘canvas’
After verifying the Diagrams.Backend.Gtk, I saw that it is builded with the old Graphics.UI.Gtk.Types from GTk2Hs which seems the cause of this error.
Is there a similar module as Diagrams.Backend.Gtk written with the GI.Gtk package ?
Do you know if in the future the diagrams backend will be build with the GI.Gtk package ?
There is another package diagrams-gi-gtk which probably contains what you are looking for.
I have recently updated it to GTK4, so you might want to use my fork until it gets merged.

How to fix cabal installation error

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

How to find source code of module I am importing

How do I find the source of the code I am importing. Like if I do
λ <Prelude>: import Graphics.EasyPlot
λ <Prelude Graphics.EasyPlot>:
How do I find that code. I do not mean an online copy of the code (Google is very good at indexing Hackage by that) but where it is on my system that I can edit. The reason is that it is a bit buggy, and I want to try and fix it. (I might submit a patch, but I just want to fix it for my own use first.)
As #ThomasDuBuisson mentioned, you many not necessarily find that on your system. One thing which I generally do is fetch it using cabal:
cabal fetch package-name
It downloads the tarballs of the package. Once you have fetched it, the entire source will be under the path where cabal puts it. In my case, it is (/home/sibi/.cabal/packages/hackage.haskell.org/package-name ). You can then untar and then build it from the cabal file which is already present there.
That being said you should probably using the version control system which the project is using as #bheklilr pointed out.

Resolving GHC 'I found a duplicate definition for symbol ...'

When running Haskell programs that import several packages like this one:
import Text.Feed.Import
import Network.HTTP
main = do
page <- simpleHTTP (getRequest "http://stackoverflow.com")
print $ page
I get an error like this one (Note: This question intends to solve the general problem, this specific case is just an example) :
GHCi runtime linker: fatal error: I found a duplicate definition for symbol get_current_timezone_seconds
whilst processing object file
/usr/lib/ghc/time-1.4.0.1/HStime-1.4.0.1.o
This could be caused by:
* Loading two different object files which export the same symbol
* Specifying the same object file twice on the GHCi command line
* An incorrect `package.conf' entry, causing some object to be
loaded twice.
GHCi cannot safely continue in this situation. Exiting now. Sorry
Reinstalling the packages (e.g. HTTP and feed in the above case) as described in this previous post doesn't help. How can I resolve this issue?
Why this error occurs
This issue is not specific to a single package (e.g. it was described here in relation to Yesod three years ago), but is caused by the different libraries you import (e.g. HTTP and feed) linking to different versions of a single library (this issue occurs only for libraries that export C-style symbols. Their symbol names are not unique. time is one of those packages.).
As denoted in the error message, the library that causes the issues in this specific case is time-1.4.0.1.
Diagnosing the exact problem
First, you need to identify which different versions exist of your library. You can do this by checking the packages using ghc-pkg describe <packagename>, or just take a look into your cabal installation directory (usually ~/.cabal/lib).
At the time of writing this, the issue was caused by both time-1.4.0.1 and time-1.4.1 being installed. By using ghc-pkg describe I figured out that feed (and only feed, in my case), linked to time-1.4.1 whereas about 100 libraries linked to time-1.4.0.1.
How to resolve
Identify the library version (of the library that causes the error, as denoted in the error message) as described above that fewer packages depend on. You'll need to rebuild all packages that depend on it. In my case this is time-1.4.1.
Then, uninstall the package:
$ ghc-pkg unregister time-1.4.1 --force
unregistering time-1.4.1 would break the following packages: feed-0.3.9.2 (ignoring)
Note that the feed package is now broken and needs to be rebuilt and reinstalled. After rebuilding however, it won't link to time-1.4.1 but time-1.4.0.1 (in my specific case). This re-linking will resolve the duplicate symbol problem.
$ cabal install feed
If the error still occurs after that, re-check all dependencies as described above. You need to make sure any library you import will show the same library it's linked to when analyzed with ghc-pkg describe <pkg>
Update: In order to find out, which packages depend on the problematic library, simply use ghc-pkg unregister without the --force flag (Thanks to John J. Camilleri for pointing that out!). Note that if no packages depend on said problematic package, it will be removed.
An alternative cause of the same problem, is when using common symbols in an external library, on windows. I have an issue with a fortran code base using the common symbols. It is better explained here> https://gitlab.haskell.org/ghc/ghc/-/issues/6107
This only happens in dynamic linking, so ghc works, but ghci does not.

Where has hSetEncoding gone?

I was fairly sure that a while back GHC added the ability to explicitly set the character encoding on a Handle. However, when I look in System.IO, I don't see anything relating to character encodings. (I have Haskell Platform 2012.4.0.0)
Am I blind, or simply mistaken?
I investigated where the function is hiding.
Summary: Make sure to use System.IO from package base, not from package haskell2010.
Details: Hoogle tells me that there is System.IO.hSetEncoding in the latest base package.
http://www.haskell.org/hoogle/?hoogle=hSetEncoding
Checking the documentation about the Haskell platform 2012.4.0.0, I see a System.IO module from the haskell2010 package. And that module doesn't seem to contain hSetEncoding.
http://lambda.haskell.org/platform/doc/2012.4.0.0/ghc-doc/libraries/haskell2010-1.1.0.1/System-IO.html
But do not despair, there seems to also be the System.IO from base which contains hSetEncoding.
http://lambda.haskell.org/platform/doc/2012.4.0.0/ghc-doc/libraries/base-4.5.1.0/System-IO.html#v:hSetEncoding
So I guess you just have to make sure that you use the System.IO from base and not from haskell2010.
Oh my God!
OK, I just figured this out.
It appears that there are two packages that both export System.IO - the base package and the haskell2010 package.
The two versions of the module are different. Specifically, only the module from base has all the character encoding stuff in it.
When you go to the locally-installed module index, it only shows you the version of System.IO that's included in haskell2010 - without all the character encoding stuff.
It appears the only way to see the version from base is to click on some other module exported from base, then click "Contents", then navigate to System.IO from there. Then it shows you the correct module!
Counter-intuitive, much? o_O
OK, so I've found my function now, but man, Haddock should probably do a better job of handling this obscure edge-case...

Resources