Question

here is what I did:

  1. makdir happstack_01

  2. cabal-dev install happstack-server

  3. write the typical helloworld.hs with "import Happstack.Server (nullConf, simpleHTTP, toResponse, ok)"

  4. ghc -threaded HelloWorld.hs -o helloworld

and I got: Could not find module `Happstack.Server'

This is so obvious wrong. But what I am more surprised is that no tutorial on google for simple thing as this.

Any intuition would be awesome!

Était-ce utile?

La solution

This is a set of instructions for a very bare-bones, Cabalized, and sandboxed build.

$ mkdir happstack01 && cd happstack01/
$ cabal init .
$ <CR><CR><CR><CR><CR><CR><CR><CR><CR>   1   <CR><CR><CR>
$ mkdir src
$ touch src/Main.hs
$ vi happstack-01.cabal

In happstack01.cabal

...

library
  exposed-modules:
    Main
  build-depends:       base >=4.6 && <4.7
                     , happstack-server
  hs-source-dirs:      src
  default-language:    Haskell2010

Then

$ cabal sandbox init
$ cabal install --only-dependencies
$ vi src/Main.hs

In src/Main.hs

import Happstack.Server

main :: IO ()
main = simpleHTTP nullConf $ return "Hello sandbox!"

Get some coffee while the sandbox builds.

$ cabal repl
> main

After this I usually add an executable entry to the Cabal file and begin to build the server from that.

Autres conseils

Since you wanted a small tutorial, I am writing up how I just got it to work. I used cabal instead of cabal-dev though (if you care, let me know and I can play around a bit more)....

> cabal install happstack-server
> mkdir sample
> cd sample

Then I created the file sample.hs

import Happstack.Server

main = simpleHTTP nullConf $ return "hello, world!"

and I compiled it

> ghc sample.hs

(This is where you seem to be having problems finding the library.... You might want to check if ~/.ghc//package.conf.d/happstack-server-7.3.1-.conf and ~/.cabal/packages/hackage.haskell.org/happstack-server/ exist to verify the download)

Then run the server

./sample

and verify that it works using curl

> curl http://127.0.0.1:8000

This should respond with

hello, world!

ok I figured this out. GHC will not regonized local sanboxed libs. at least my GHC --version 7.6.3 does not. So I will have to cabalise my project in order to make sandboxed libs work.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top