I'm new to Haskell. How come when I try to use Days from Data.Time I get this error:
Could not find module `Data.Time':
It is a member of the hidden package `time-1.1.4'.
Perhaps you need to add `time' to the build-depends in your .cabal file.
I am importing Data.List and Control.Monad, and neither gives me this error message, but the code import Data.Time does.
What am I missing?
Thanks for the help!
EDIT: I'm getting a similar error message when I use: import Directory
Thanks guys, your answers got me on track!
Fire up Leksah with this project, open the package menu and select "edit package" from it. Now, choose "dependencies" and add the dependency you need (in your case time). You may also choose a version.
PS: Don't forget to hit the "save" button afterwards. (I think this is a design failure...).
Just edit the projects .cabal file, usually in the top directory named ProjectName.cabal and find the line(s) with "build-depends:" and add "time" to this list. No need for Leksah, unless you already use it.
EDIT: To answer your question of "why now and not with module X"
Data.Time is in the time package, which evidently isn't included in your build dependencies. Similar story for the Directory module. You don't get these errors with Data.List or Control.Monad because they are part of the base package which I'll bet is in your build-deps.
On a side note, it is worth taking time to learn what modules are in base and what functionality those modules provide. Base is rather large and very useful.
Related
I need to find out why some module gets included into compilation.
There is some class that should not be included and I think there are some unused imports or bad architecture that requires unnecessary imports. Is there a way to find which modules import some module, which modules import these modules that include this module, and so on, tracking that down to main class of application?
You could use -D dump-dependencies for this, in which case the compiler will generate two files that can be used to follow the dependency graph in both directions:
dump/<target>/.dependants.dump
dump/<target>/.dependencies.dump
There is also a handy online tool created by Mark Knol that helps a lot with analyzing these files. To answer the question "what does Array depend on?", you can just upload the two files and enter "array" into the search field:
Conveniently, the results are also clickable.
I've just came up with very simple idea: just delete this file and there will be compilation errors in places where this module is imported.
I am trying to create a Python package. You can have a look at my awful attempt here.
I have a module called imguralbum.py. It lives in a directory called ImgurAlbumDownloader which I understand is the name of the package -- in terms of what you type in an import statement, e.g.
import ImgurAlbumDownloader
My module contains two classes ImgurAlbumDownloader and ImgurAlbumException. I need to be able to use both of these classes in another module (script). However, I cannot for the life of me work out what I am supposed to put in my __init__.py file to make this so. I realize that this duplicates a lot of previously answered questions, but the advice seems very conflicting.
I still have to figure out why (I have some ideas), but this is now working:
from ImgurAlbumDownloader.imguralbum import ImgurAlbumDownloader, ImgurAlbumException
The trick was adding the package name to the module name.
It sure sounds to me like you don't actually want a package. It's OK to just use a single module, if your code just does one main thing and all its parts are closely related. Packages are useful when you have distinct parts of your code that might not all be needed at the same time, or when you have so much code that a single module would be very large and hard to find things in.
I would like to look at the code of functions defined in modules, such as Data.List or Data.Map.
I can import Data.List module with
import Data.List
and then I can use the functions nub or sort.
I would like to know where I can find these functions to look at their code.
In which directory are the modules installed by default?
PS: Windows 8.1, I installed Haskell Platform.
That directory contains compiled modules, so you wouldn't be able to read the source there.
What you can do is to find your function in online documentation and then click "Source" on the right.
As #arrowd notes in his answer,
That directory contains compiled modules, so you wouldn't be able to
read the source there.
The GHC repo (and its Github mirror) can be directly browsed, but there is an easier way:
Use Hoogle or Stackage to find the package where the module/function resides
Note that Hoogle and Stackage are case-sensitive. (It's best to look up modules with their capitalized names.)
A query for sort in Hoogle yields a list similar to the one below. Stackage has a slightly different style, but the basics are the same (mostly because it uses Hoogle for lookup). The lines in green under the result headings show the name(s) of the containing
(1) package(s) (in small caps) and
(2) module(s) (capitalized).
There can be multiple functions with the same name, but the module and package name helps to choose the right one.
Click on the function/module name
Click on "#Source"
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.
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...