packages feed

happs-tutorial-0.7: templates/understandinghappstypes.st

<p>I find it helpful to have ghci tell me about the types in the code I am reading. Here is a snip of ghci output.</p>

<p>
<br>*Main>:i simpleHTTP
<br>simpleHTTP :: (ToMessage a) => Conf -> [ServerPartT IO a] -> IO ()
<br>  	-- Defined in HAppS.Server.SimpleHTTP
<br>*Main>:i Conf
<br>data Conf = Conf {port :: Int}
<br>        -- Defined in HAppS.Server.HTTP.Types
<br>*Main> :i ServerPartT
<br>newtype ServerPartT m a
<br>  = ServerPartT {unServerPartT :: Request -> WebT m a}
<br>  	-- Defined in HAppS.Server.SimpleHTTP
<br>instance [overlap ok] (Monad m) => Monad (ServerPartT m)
<br>  -- Defined in HAppS.Server.SimpleHTTP
<br>*Main> :i WebT
<br>newtype WebT m a = WebT {unWebT :: m (Result a)}
<br>  	-- Defined in HAppS.Server.SimpleHTTP
<br>instance [overlap ok] (Monad m) => Monad (WebT m)
<br>  -- Defined in HAppS.Server.SimpleHTTP
</p>

<p>So basically what this tells you is that the meat of a Happstack application is a list of ServerParts, which themselves are a wrapper over a function that takes an HTTP request to a response.</p>

<p>I use ghci info a lot, and you should too as you are learning Happstack.  It's very useful for understanding how various pieces of HAppS fit together.

<p><a href="http://www.haskell.org/haskellwiki/HAppS_tutorial">HAppsTutorial2</a> at the haskell wiki has a more in-depth
look at thinking behind Happstack and the Happstack type system. </p>