2

I want to install, and use Happstack, and what should of taken 10 minutes, has been bugging me all day. First off, I had to wrestle with Cabal, and eventually gutted it out, and installed a fresh copy, and updated it:

# I use Fedora 16... 
yum remove cabal-install
...
yum install cabal-install
...
cabal update
...
# I was told that a new version was available.
cabal install cabal-install
...
cabal install happstack-server

None of these commands failed (or at least they didn't give the impression that they did.)

With it now installed, I decided to try and build the first, simple example found in the Crashcourse guide.

I have it written as:

-- server.hs
module Main where

import Happstack.Server (nullConf, simpleHTTp, toResponse, ok)

main :: IO()
main = simpleHTTP nullConf $ ok "Hello World!"

When I try to compile it with GHC using the commandline of:

ghc --make -threaded server.hs -o server 

I get the following error:

server.hs:3:8:
    Could not find module `Happstack.Server':
      Use -v to see a list of the files searched for.

and using the suggested -v option gives:

Glasgow Haskell Compiler, Version 7.0.4, for Haskell 98, stage 2 booted by GHC version 7.0.4
Using binary package database: /usr/lib/ghc-7.0.4/package.conf.d/package.cache
wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-6bf7b03ebc9c668817e4379b6796c0c2
wired-in package integer-gmp mapped to integer-gmp-0.2.0.3-4c5ab8b517f0b5d4ecf2153d5dfb7f41
wired-in package base mapped to base-4.3.1.0-4582a5bc64f22f03f6d960b4f15c981f
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.5.0.0-958de6d18727479331372229849ac6b8
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -static
*** Deleting temp files:
Deleting: 
*** Deleting temp dirs:
Deleting: 
ghc: no input files

Honestly, I'm having a hard time interpreting that. Anyways, I decided it was time to Google (again!) That lead me to this similar question (Which is messy and not very useful by the way...), and it suggested trying to load the module in GHCi.

I gave it a shot, and to my surprise, this works:

> :m Happstack.Server
> simpleHTTP nullConf $ ok "Hello World!"
> 
> ...MODULE LOADING INFORMATION HERE...

as well as this:

> :l server
> main

Both run and behave as they should.

So in short, this is weird, Cabal is a hassle, and I don't really have much experience with the basic Haskell toolset (yet.)

Anyone got any ideas on how to fix this? Thanks in advance! :)

Community
  • 1
  • 1
Miguel
  • 1,966
  • 2
  • 18
  • 32
  • Try compiling without --make or --threaded (and use -O2 while you are at it). Also check that ghci is invoking the same version of ghc since ghc keeps a different package cache per ghc version. – Gabriella Gonzalez Oct 02 '12 at 01:53
  • @GabrielGonzalez I tried compiling it like you said, but it hasn't made any difference. Also, how can I check which version of GHC is being invoked by GHCi? – Miguel Oct 02 '12 at 02:44
  • 1
    @Miguel Run `ghc --version` and `ghci --version`. – Ptharien's Flame Oct 02 '12 at 05:43
  • 1
    You might also post the output from `ghc-pkg --list`. – MathematicalOrchid Oct 02 '12 at 08:49
  • It is still very likely that your .cabal directory is wedged somehow. I find the most informative way to figure out what is going on is to run ghci (with out any arguments/filenames/etc) and then enter `:set -v` at the prompt. My expectation is that it will say it is hiding `happstack-server` because it depends on some package that is broken. There might be a long chain of broken things until you get down to the root broken package. – stepcut Oct 04 '12 at 03:32

1 Answers1

1

It's usually best to write your own .cabal file and use Cabal to build your project. Try cabal init to get started quickly, and make sure to add happstack-server to the build-depends of your executable or library.

If you really want to use ghc --make, perhaps try passing something like -package happstack-server to it.

Dag
  • 682
  • 5
  • 10