GHCi看到Happstack.Server,但GHC没有。这是怎么回事?

时间:2012-10-02 01:44:03

标签: haskell cabal happstack

我想安装,并使用Happstack,应该花10分钟,一直困扰着我。首先,我不得不与Cabal搏斗,并最终将它掏出来,并安装了一份新的副本,并更新了它:

# 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

这些命令都没有失败(或者至少他们没有给人留下他们的印象。)

现在已安装,我决定尝试构建Crashcourse guide中的第一个简单示例。

我把它写成:

-- server.hs
module Main where

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

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

当我尝试使用GHC使用命令行编译它时:

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

我收到以下错误:

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

并使用建议的-v选项提供:

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

老实说,我很难解释这一点。无论如何,我决定是时候谷歌了(再次!)这导致我this similar question这是凌乱的,顺便说一下也不是很有用...... ),它建议尝试在GHCi中加载模块。

我试了一下,令我惊讶的是,这有效:

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

以及:

> :l server
> main

既奔跑又表现得如此。

所以简而言之,这很奇怪,Cabal很麻烦,而且我对基本的Haskell工具集没有多少经验(但是。)

任何人都对如何解决这个问题有任何想法?提前致谢! :)

1 个答案:

答案 0 :(得分:1)

通常最好编写自己的.cabal文件并使用Cabal来构建项目。尝试cabal init快速入门,并确保将happstack-server添加到您的可执行文件或库的build-depends

如果你真的想使用ghc --make,也许可以尝试将类似-package happstack-server的内容传递给它。