Search code examples
haskellcabal-dev

cabal-dev install Happstack-server how


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!


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.