Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The fastCGI package is actually a extension of the <a href="http://hackage.haskell.org/package/cgi-3001.1.8.2" rel="nofollow">cgi</a> package, which includes the protocol types for receiving request data and returning result pages. I'd suggest using CGI to start with, and then move to fastCGI once you know what you are doing.</p> <p>You might also want to look at <a href="http://www.haskell.org/haskellwiki/Practical_web_programming_in_Haskell" rel="nofollow">this tutorial</a>.</p> <p>Edit to answer questions about the tutorial:</p> <p>"Maybe a" is a type that can either contain "Just a" or "Nothing". Most languages use a null pointer to indicate that there is no data, but Haskell doesn't have null pointers. So we have an explicit "Maybe" type instead for cases when the data might be null. The two constructors ("Just" and "Nothing") along with the type force you to explicitly allow for the null case when it might happen, but also let you ignore it when it can't happen.</p> <p>The "maybe" function is the universal extractor for Maybe types. The signature is:</p> <pre><code>maybe :: b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b </code></pre> <p>Taking the arguments from front to back, the "Maybe a" third argument is the value you are trying to work with. The second argument is a function called if the third argument is "Just v", in which case the result is "f v". The first argument is the default, returned if the third is "Nothing".</p> <p>In this case, the trick is that the "cgiMain" function is called twice. If it finds an input field "name" then the "mn" variable will be set to (Just "Joe Bloggs"), otherwise it will be set to (Nothing). (I'm using brackets to delimit values now because quotes are being used for strings).</p> <p>So the "maybe" call returns the page to render. The first time through no name is provided, so "mn" is (Nothing) and the default "inputForm" page is returned for rendering. When the user clicks Submit the same URL is requested, but this time with the "name" field set, so now you get the "greet" function called with the name as an argument, so it says "Hello Joe Bloggs".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload