Cabal failing to install vector-space package - haskell

When I try to install the spacepart package using cabal install it tries to compile a dependency vector-space but when vector-space tries to compile a module it exports "Data.LinearMap" I get the error "Not in scope type constructor or class "HasTrie". After I did some digging HasTrie is a class exported by the MemoTrie package. Thing is I have MemoTrie installed and MemoTrie exports "HasTrie". What is wrong here?
Also this stack overflow post doesnt help so this isnt a duplicate question: Haskell package vector-space fails at compile time
-Thank you for your time

As far as I can see from browsing on Hackage, spacepart is fixed to use a very old version of vector-space (0.5.*), and that version's Data.LinearMap contains the suspicious import line
import Data.MemoTrie ((:->:)(..))
which simply doesn't import HasTrie. My guess is that at some time in the past, this actually worked, because (:->:) is a data family defined inside HasTrie, but that GHC has since been changed so it doesn't.
Possible dirty fix: I note that until 0.5.2, it simply says
import Data.MemoTrie
I just tried installing with
cabal install spacepart vector-space-0.5.2
and it seemed to work.

Related

How do you import Data.Heap?

Sorry for such a dumb question. I'm trying to import Data.Heap, but I get this error message:
> import Data.Heap
<no location info>: error:
Could not find module ‘Data.Heap’
Perhaps you meant
Data.Map (from containers-0.5.7.1#containers-0.5.7.1)
Haven't had trouble with other imports.
Thanks.
As was described in the comments, you need to install the package which contains the module Data.Heap. (See this related question on the difference between packages and modules in Haskell)
On the Hackage page, in the upper left-hand corner you will see the name and version of the package you are looking at:
If you are using stack, then add heap to your build-depends section of project.cabal file, and rebuild. If you are just using cabal, simply run cabal install heap to get the most recent version of the package installed on your system.

Craft3e: cabal install not in scope: Applicative

I am attempting to install the code for "Haskell: The Craft of Functional Programming", 3rd edition.
I'm using GHCi, version 7.6.3 on Centos version 7.
Then:
cabal unpack Craft3e
cd Craft3e-0.1.1.0/
cabal install
...
[29 of 67] Compiling CalcParseLib ( Calculator/CalcParseLib.hs, dist/build/CalcParseLib.o )
Calculator/CalcParseLib.hs:132:10:
Not in scope: type constructor or class `Applicative'
Failed to install Craft3e-0.1.1.0
cabal: Error: some packages failed to install:
Craft3e-0.1.1.0 failed during the building phase. The exception was:
ExitFailure 1
I have attempted this installation multiple times, but cannot
overcome this error.
Could I use something other than "cabal install"?
I have plenty to learn about Haskell before I get to this example,
but it would be great to know the installation is fine! :)
You have three options:
Install an older version of the Craft3e package, with e.g. cabal unpack Craft3e-0.1.0.10.
Find Calculator/CalcParseLib.hs in the source files you have downloaded with cabal unpack and add a...
import Control.Applicative
... line next to the other import lines at the beginning. I suspect you will have to do the same with other modules, if the same error shows up elsewhere after you do this change, and there might be other issues of a similar nature.
Install a newer version of GHC (7.6.3 is from 2013). Though the default CentOS repositories won't offer that, there are other options, such as an unofficial Fedora repository and a manual installation. See this page for instructions.
#3 is the definitive solution. If you just want to get started with the book right now, though, you can go for #1 and leave the reinstall for later.
For the sake of reference, here is a brief explanation of the problem (I will use some unfamiliar terms, but you will soon enough learn about them as you study Haskell). There is an important type class called Applicative which, for historical reasons, wasn't as well integrated with the rest of the core libraries as it should be. This situation was corrected in GHC 7.10, which both included Applicative in the Prelude (the module which is imported by default in Haskell programs) and made it necessary to add Applicative instances in a number of places where they were missing. The code in the Craft3e package was updated so that these Applicative instances were in place (cf. this entry in the book's blog), but the import Control.Applicative line, which would be necessary to make the updated code work in older GHCs that do not have Applicative in the Prelude, wasn't added, leading to the error that you are seeing.

Haskell: where is Data.Numbers.Primes library?

I tried importing Data.Numbers.Primes
import Data.Numbers.Primes
runhaskell gave me:
5.hs:1:8:
Could not find module `Data.Numbers.Primes'
Use -v to see a list of the files searched for.
ghci gave me:
<no location info>:
Could not find module `Data.Numbers.Primes'
It is not a module in the current program, or in any known package.
I tried to install Data.Numbers.Primes through cabal, but I got:
cabal update
...
cabal install Data
cabal: There is no package named 'Data'.
You may need to run 'cabal update' to get the latest list of available
packages.
cabal install Data.Numbers.Primes
cabal: The file does not exist 'Data.Numbers.Primes'.
help?
The package you're looking for is called primes.
There's no rule that the package will be called the same as its top-level module name. Typically, packages put themselves under whatever makes sense, but that's pretty much arbitrary. When in doubt, Hackage search helps.

Haskell Hidden Packages: Data.HashSet

I'd like to use Data.HashSet in Haskell. So I put import Data.HashSet at the beginning of my program. GHCi complains: Could not find module Data.HashSet.
My questions are:
How can I get Data.HashSet to work?
I've read somewhere that this is part of a hidden module or package. Why is the module hidden? Does "hidden" mean that I should not use it?
If I should not use it, is there a better alternative for a haskell data structure with a near-constant lookup time?
Data.HashSet is a module in the unordered-containers package, and also in the hashmap package. If you have either package installed,
import Data.HashSet
should work out of the box, since it is an exposed module of both packages. To install it (using unordered-containers, since that is the commonly used one),
cabal update
cabal install unordered-containers --dry-run
-- check that it wouldn't reinstall anything, if all's fine
cabal install unordered-containers

Haskell Web Framework

I'm creating simple web application using haskell. First I used Snap in front and I was able to run the application, but I want to add user input to the application.
I couldn't find a way to get user input parameters to the function. How might I do that?
Other thing, I also used Happstack framework, I can not import "Happstack.Server". I use cabal installation configure Happstack. It was successfully installed, but when I try to import to "Happstack.Server", it gives me an error:
<no location info>:
Could not find module `Happstack.Server':
it is not a module in the current program, or in any known package.
If I run my program using ghc --make HelloWorld.hs -v, I get:
Glasgow Haskell Compiler, Version 6.12.1, for Haskell 98, stage 2 booted by GHC version 6.12.1
Using binary package database: /usr/lib/ghc-6.12.1/package.conf.d/package.cache
Using binary package database: /home/udeshika/.ghc/i386-linux-6.12.1/package.conf.d/package.cache
package happstack-6.0.0-0f0c2507d590ebd01e8601c8667ec809 is unusable due to missing or recursive dependencies:
happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-ixset-6.0.0-4e1b5476a551c4501c5734b22e0b280d is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c
package happstack-server-6.0.3-6d71e7bb09489130538fb851a694b927 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f network-bytestring-0.1.3.4-937fd511949a2d5ef21e86ec5306c791 sendfile-0.7.3-137cf51cc81a277d724637a7cd1e6b09
package happstack-state-6.0.0-0e753e61d7092b6a5139e473113877a1 is unusable due to missing or recursive dependencies:
happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9
package happstack-util-6.0.0-4156bd1331b7a0d62e0087101c9eba1c is unusable due to missing or recursive dependencies:
hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 network-2.2.1.7-72dad7eb07ee7a683982f7475b8a449f
package hslogger-1.1.4-90c801c802eec92e4e6a6f83d24d58d9 is unusable due to missing or recursive dependencies:
...................
Snap's getParam function allows you to get HTTP request parameters specified by the user. These can come in the post body of a form submission or from the query string. For example, consider the following code:
site = dir "mypage" pageHandler
pageHandler = do
val <- getParam "foo"
writeBS $ maybe "no value" id val
If I request the url "myapp.com/mypage?foo=bar", then I will see "bar" as the response. If I leave off the "?foo=bar" part, then it will return "no value".
1) Check out that Happstack is actually installed and exposed:
ghc-pkg list | grep Happstack
2) What if you try to import Happstack.Server in ghci ?
3) Better use cabal-dev or capri for installing such things and making a sandbox
4) Snap and Yesod a quite new and they are under heavy development, Happstack is pretty
stable and solid.
5) What OS are you using? How did your installed the haskell? Ubuntu + haskell 6.12 + Happstack work out of the box
Regarding to the log, seems that cabal packages are messed up somehow. I recommend you to remove all packages from the .cabal and .ghc, reinstall cabal, then install cabal-dev as explained here:
http://www.reddit.com/r/haskell/comments/f3ykj/psa_use_cabaldev_to_solve_dependency_problems/
and then have fun with Happstack. Some guys actually use capri, it works as well.
Your installation is messed up. Unfortunately, cabal does that sometimes.
Your best bet is use 'ghc-pkg unregister ' to remove all the happstack packages, hslogger, and sendfile. Make sure they are removed from the user and global package databases. (ghc-pkg list will show you what is installed). Once you have the old versions removed, do, cabal update and the cabal install happstack. Then things should work.
What do you mean by 'user input' ? Do you mean html forms? Or something else ?
This section of the crash course may address your needs:
http://www.happstack.com/docs/crashcourse/RqData.html
It is also possible to use digestive-functors with Happstack to get type-safe form processing. Unfortunately, this is not well documented yet. Though I believe the disgestive-functors source code does include a working Happstack example.

Resources