Baby Steps with HAppS v0.9.1

1 vue
Accéder directement au premier message non lu

eugene.g...@gmail.com

non lue,
11 déc. 2007, 07:10:1711/12/2007
à HAppS
Baby Steps with HAppS v0.9.1

1. goal
2. installation
3. hello world
4. xhtml
5. xhtml.strict (custom response)
6. credits

1. GOAL

To document the steps taken as I am trying out
the new champion on the horizon -- HAppS.

I will start from the simplest server configuration without a state
system
to get going quickly.

2. INSTALLATION

The first obstacle, and the hardest one for newbies like me, is to
have a
working installation. Yampa has the same problem but that's a
different story.
While Haskell may be the best language on the planet right now, it
does lack
well developed tools like Maven. Let's hope this will be resolved
in the near future.

I had already unsuccessfully attempted to play around with Happs
earlier.
So i had older version of HAppS lying around from the already split
repositories. If you are in the same situation, simply
replace "darcs get xxxx" with "cd HAppS-xxx && darcs pull && cd .."

the first thing to do is get the dependencies:
hslogger, syb-with-class, NewBinary, HTTP, Crypto, and HaXml-1.13.2
and of course ghc-6.8.1

syb will not install from the Hackage on my ghc-6.8.1
i had to get it from darcs:

darcs get http://happs.org/HAppS/syb-with-class
cd syb-with-class
runhaskell Setup.hs configure
runhaskell Setup.hs build
sudo runhaskell Setup.hs install
cd ..

hslogger wont install from Hackage too. use this:

darcs get --partial http://darcs.complete.org/hslogger

Haxml must be below version 1.14:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HaXml-1.13.3

wget http://hackage.haskell.org/packages/archive/HaXml/1.13.3/HaXml-1.13.3.tar.gz
tar zxvf HaXml-1.13.3.tar.gz
cd HaXml-1.13.3
runhaskell Setup.hs configure
runhaskell Setup.hs build
sudo runhaskell Setup.hs install
cd ..

Before configuring NewBinary, make sure that NewBinary.cabal has this
line:

Build-Depends: base, array

Before configuring Crypto, make sure that Crypto.cabal has this line:

Build-Depends: base, mtl, QuickCheck, HUnit, NewBinary,
containers, old-time, array, random, pretty

The rest (HTTP) can be installed from Hackage using latest versions
without problems.

Follow the instructions on http://happs.org/#cabal to get HAppS
installed.
You can skip installing HAppS-Begin,
but get it in any case to check out examples.

3. HELLO WORLD

Finally Happs is installed. Now let's make the simplest possible
webapp.
Create a file named Server.hs with the following:

{-# OPTIONS -fglasgow-exts #-}
import HAppS
main = do
simpleHTTP [method GET $ "Hello, World!"]
getLine

now to compile and run it:

ghc --make Server.hs
./Server

the application will wait for a newline to quit. visit your brand new
webapp at
http://localhost:8000/

4. XHTML

It's very simple to have an XHtml output instead of plain text with
Text.XHtml
You need to install xhtml package from Hackage.

Modify Server.hs to read:

{-# OPTIONS -fglasgow-exts #-}
import HAppS
import Text.XHtml.Transitional hiding (method)

main = do
simpleHTTP [method GET $ response1]
getLine

response1 = ok $
(header $ thetitle << "My First Page")
+++
(body $ h1 << "Hello, World!")

Compile and run again. we now have XHtml!

5. CUSTOM RESPONSE

Note that i am not calling any of the rendering functions.
HAppS polymorphs on the response type. In the case of Html,
it assumes Text.XHtml.Transitional and calls prettyHtml.

I would like to have a Strict XHtml and not have a pretty-print as it
can
cause problems in some cases. To achieve that we will create a new
response
type and implement ToMessage class like so:

{-# OPTIONS -fglasgow-exts #-}

import HAppS
import Text.XHtml.Strict hiding(method)
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as L

newtype XhtmlStrict = XhtmlStrict Text.XHtml.Strict.Html
instance ToMessage XhtmlStrict where
toContentType _ = B.pack "application/xhtml+xml"
toMessage (XhtmlStrict html) = (L.pack . renderHtml) html

main = do
simpleHTTP [method GET $ response1]
getLine

response1 = ok $ XhtmlStrict $
(header $ thetitle << "My First Page")
+++
(body $ h1 << "Hello, World!")

That's it for now.

6. CREDITS

Lemmih from #happs@freenode for providing assistance.

Thomas Hartman

non lue,
11 déc. 2007, 10:35:0411/12/2007
à HA...@googlegroups.com,HAppS

>The first obstacle, and the hardest one for newbies like me, is to
>have a
>working installation. Yampa has the same problem but that's a
>different story.
>While Haskell may be the best language on the planet right now, it
>does lack
>well developed tools like Maven. Let's hope this will be resolved
>in the near future.


What does Maven provide that cabal-install doesn't have?

HAppS is hard to install because there is no dependable install path and heads of the variegated repos  are out of sync more often than not. And it's not just hard for newbies, it's hard for everybody. If you look at irc logs there are numerous experience reports of people getting stuck on the install stuff for *days*.

Any word on when there will be a darcs-tagged or tarballed installation path? I seem to remember something about this coming out after ghc 6.8.2 because of some 6.8.1 bug, but I don't understand why that should stop a repo unification and tagged build.  Since even with the phantom type bug, HAppS seems to have enough functionality to hack on.

With a stable install base (tar.gz or darcs tagged) one could post install scripts and the like to the mailing list to further automate things and make life easier, but lacking that it's like pushing on a string. There's no reason to believe that the instructions grigoriev offered up today will work tomorrow.

Another thing that would help is commitment to an API, along with tests that show the API in use. If the API changes, the tests could change to show the new use. Then even if the documentation got out of date (a frequent occurrence), tests in sync with code would be a baseline guarantee of functionality.

One constructive thing to note is that even at this point anyone could tar up and offer for download a "known good" install path. If you're going to offer instructions like this I would post a tar of the known good install as well, otherwise the chance of darcs get working against it deteriorate pretty fast.
'
To sum it up, it's heartening that people are sharing their installs stories, but disheartening that they have to.

t.




"eugene.g...@gmail.com" <eugene.g...@gmail.com>
Sent by: HA...@googlegroups.com

12/11/2007 07:10 AM

Please respond to
HA...@googlegroups.com

To
HAppS <HA...@googlegroups.com>
cc
Subject
---

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.

David Bergman

non lue,
11 déc. 2007, 11:12:3411/12/2007
à HA...@googlegroups.com
On Dec 11, 2007, at 10:35 AM, Thomas Hartman wrote:


>The first obstacle, and the hardest one for newbies like me, is to
>have a
>working installation. Yampa has the same problem but that's a
>different story.
>While Haskell may be the best language on the planet right now, it
>does lack
>well developed tools like Maven. Let's hope this will be resolved
>in the near future.


What does Maven provide that cabal-install doesn't have?

Well, for one, there is no "one click" installer for cabal-install ;-) If people would have to download a lot of stuff - manually ensuring right versions - to get Maven working, it would not have been a hit. Wait! Maven (version 2) actually is no hit, for some weird reason, but it should be ;-)

So, I suggest providing a bundle with the bare necessities for cabal-install, to make it easy to install. Or, if a kind soul - me? - would provide compiled versions of cabal-install for the most common platforms!


HAppS is hard to install because there is no dependable install path and heads of the variegated repos  are out of sync more often than not. And it's not just hard for newbies, it's hard for everybody. If you look at irc logs there are numerous experience reports of people getting stuck on the install stuff for *days*.

One can always use SearchPath and pray that the darcs trunks are coherent at this hour. I am a newbie to Cabal - but would not classify myself as a newbie to Haskell - and it took me many hours to set it up, so I agree.

Any word on when there will be a darcs-tagged or tarballed installation path? I seem to remember something about this coming out after ghc 6.8.2 because of some 6.8.1 bug, but I don't understand why that should stop a repo unification and tagged build.  Since even with the phantom type bug, HAppS seems to have enough functionality to hack on.

With a stable install base (tar.gz or darcs tagged) one could post install scripts and the like to the mailing list to further automate things and make life easier, but lacking that it's like pushing on a string. There's no reason to believe that the instructions grigoriev offered up today will work tomorrow.

Yep, a third column in the SearchPath map, providing a darcs tag would be neat.

Another thing that would help is commitment to an API, along with tests that show the API in use. If the API changes, the tests could change to show the new use. Then even if the documentation got out of date (a frequent occurrence), tests in sync with code would be a baseline guarantee of functionality.

A 7-liner at least. That should not be too hard to maintain. I have to step through most of ...Server and ...State to understand the intended use of 0.9.1(a). Maybe we - as users - could provide such a 7-liner, after spending those minutes/hours trying to understand the usage pattern to a Wiki page somewhere, though, since we do not help out with the coding. That will leave more time for The Doers to Do Their Thing: create an even better HAppS ;-)

One constructive thing to note is that even at this point anyone could tar up and offer for download a "known good" install path. If you're going to offer instructions like this I would post a tar of the known good install as well, otherwise the chance of darcs get working against it deteriorate pretty fast.

You mean of the whole shabang, including dependencies, or just for HAppS itself? The latter could - of course - be handled via darcs tags, and the former *could* be handled via darcs tags in SearchPath, although that would require that Other Developers tagged their creations properly...

To sum it up, it's heartening that people are sharing their installs stories, but disheartening that they have to.

Yep, feels good not being the only ugly kid in class :-)

/David

eugene.g...@gmail.com

non lue,
12 déc. 2007, 04:28:1012/12/2007
à HAppS

>
> What does Maven provide that cabal-install doesn't have?
>

i love the idea of cabal-install and i am the first in the line to get
the first release. i did have unpleasant experiences with the 0.x
versions of it. let's not compare a package manager with a project
manager. cabal-install is more related to cpan shell than maven. the
features i am looking for are automatically fetching the right
versions of all the dependencies and putting them in the build path so
your other project that depends on a different version of a module in
question does not break. i am in no way! implying that haskell/cabal/
happs sucks. i love them and understand that these issues need time.
the purpose of the above post was to offer some help to newbies as i
was looking for and could rarely find any except in #happs and
#haskell. and you don't want to be a continuous bother.

> One constructive thing to note is that even at this point anyone could tar
> up and offer for download a "known good" install path. If you're going to
> offer instructions like this I would post a tar of the known good install
> as well, otherwise the chance of darcs get working against it deteriorate
> pretty fast.

yes that is a good point.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message