1

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!

gzmask
  • 303
  • 2
  • 9
  • What version of cabal are you using? What version of Happstack did you try to install? The latest version of cabal adds the "sandbox" feature which works pretty well for installing project specific packages, have you tried it out? – bheklilr Dec 29 '13 at 02:26
  • Yes, I have tried 'cabal sandbox init' followed by 'cabal install happstack-server' as well, then ghc gives same error. I checked the .cabal-sandbox and happstack is there. so I guess ghc is not checking sanboxed libraries at all? – gzmask Dec 29 '13 at 02:46
  • GHC itself does not check the sandbox, you should be writing a .cabal file and using `cabal build` in order to build your project. – bheklilr Dec 29 '13 at 04:03

3 Answers3

3

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!
jamshidh
  • 12,002
  • 17
  • 31
  • Thanks for taking your time to write this basic how-to. But I wanted a sandboxed environment and I think GHC does not check for sandboxed libs, yet. – gzmask Dec 29 '13 at 03:07
3

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.

J. Abrahamson
  • 72,246
  • 9
  • 135
  • 180
0

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.

gzmask
  • 303
  • 2
  • 9