ContentsIndex
GuaranteedCGI
Contents
Basics
Links and Images
Forms and Widgets
Form Creation
Form Submission
Textual Input
Checkbox
Button
Image
Selection Box
File
Handle Manipulation
Attribute Shortcuts
Advanced
Installing Translators
Outputable Stuff
Predefined Types for Input Fields
Lowlevel Options
Servlets
HTML and Style
Experimental Stuff
Synopsis
data CGI a
ask :: WithHTML HTML CGI a -> CGI ()
tell :: CGIOutput a => a -> CGI ()
io :: (Read a, Show a) => IO a -> CGI a
run :: CGI () -> IO ()
once :: (Read a, Show a) => CGI a -> CGI a
forever :: CGI () -> CGI ()
htell :: WithHTML HTML IO () -> CGI a
askOffline :: WithHTML HTML CGI a -> (Element -> IO ()) -> CGI ()
data Image
internalImage :: FreeForm -> String -> WithHTML x CGI Image
externalImage :: URL -> String -> WithHTML x CGI Image
makeImg :: AdmitChildIMG y => Image -> HTMLField IMG y ()
makeRef :: (AdmitChildA y, Monad m) => String -> WithHTML A m () -> CGI (WithHTML y m ())
makePopupRef :: AdmitChildA y => String -> String -> HTMLField A y ()
makeA :: AdmitChildA y => String -> String -> HTMLField A y ()
backLink :: (AdmitChildA x, Monad m) => HTMLCons A x m ()
hlink :: (AdmitChildA y, Monad m) => URL -> HTMLCons A y m ()
popuplink :: (AdmitChildA y, Monad m) => String -> URL -> HTMLCons A y m ()
restart :: CGI ()
type HTMLField x y a = WithHTML x CGI () -> WithHTML y CGI a
makeForm :: AdmitChildFORM y => WithHTML FORM CGI a -> WithHTML y CGI ()
standardQuery :: String -> WithHTML FORM CGI a -> CGI ()
submit :: (AdmitChildINPUT y, InputHandle h) => h INVALID -> (h VALID -> CGI ()) -> HTMLField INVALID y ()
submit0 :: AdmitChildINPUT y => CGI () -> HTMLField INPUT y ()
defaultSubmit :: (AdmitChildINPUT y, InputHandle h) => h INVALID -> (h VALID -> CGI ()) -> HTMLField INPUT y ()
resetField :: AdmitChildINPUT y => HTMLField INPUT y (InputField () INVALID)
activeInputField :: (AdmitChildINPUT y, Reason a, Read a) => (a -> CGI ()) -> HTMLField INPUT y ()
activate :: AdmitChildINPUT y => (a -> CGI ()) -> HTMLField INPUT y (InputField a INVALID) -> HTMLField INPUT y ()
submitx :: AdmitChildINPUT y => DTree INPUT y -> HTMLField INPUT y ()
data DTree x y
dtleaf :: CGI () -> DTree x y
dtnode :: InputHandle h => h INVALID -> (h VALID -> DTree x y) -> DTree x y
inputField :: (AdmitChildINPUT y, Reason a, Read a) => HTMLField INPUT y (InputField a INVALID)
textInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField String INVALID)
passwordInputField :: (AdmitChildINPUT y, Reason a, Read a) => HTMLField INPUT y (InputField a INVALID)
makeTextarea :: AdmitChildTEXTAREA y => String -> HTMLField TEXTAREA y (InputField String INVALID)
checkboxInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField Bool INVALID)
makeButton :: AdmitChildINPUT y => HTMLField INPUT y (InputField Bool INVALID)
data RadioGroup a x
radioGroup :: Read a => WithHTML x CGI (RadioGroup a INVALID)
radioButton :: (AdmitChildINPUT y, Show a) => RadioGroup a INVALID -> a -> HTMLField INPUT y ()
radioError :: AdmitChildIMG x => RadioGroup a INVALID -> WithHTML x CGI ()
imageField :: AdmitChildINPUT y => Image -> HTMLField INPUT y (InputField (Int, Int) INVALID)
selectMultiple :: (AdmitChildSELECT y, Eq a) => (a -> String) -> [a] -> [a] -> (Int, Int) -> HTMLField SELECT y (InputField [a] INVALID)
selectSingle :: (AdmitChildSELECT y, Eq a) => (a -> String) -> Maybe a -> [a] -> HTMLField SELECT y (InputField a INVALID)
selectBounded :: (AdmitChildSELECT y, Enum a, Bounded a, Read a, Show a, Eq a) => Maybe a -> HTMLField SELECT y (InputField a INVALID)
fileInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField FileReference INVALID)
data InputField a x
data VALID
data INVALID
value :: HasValue i => i a VALID -> a
class InputHandle h
data F0 x = F0
data F1 a x = F1 (a x)
data F2 a b x = F2 (a x) (b x)
data F3 a b c x = F3 (a x) (b x) (c x)
data F4 a b c d x = F4 (a x) (b x) (c x) (d x)
data F5 a b c d e x = F5 (a x) (b x) (c x) (d x) (e x)
data F6 a b c d e f x = F6 (a x) (b x) (c x) (d x) (e x) (f x)
data F8 a b c d e f g h x = F8 (a x) (b x) (c x) (d x) (e x) (f x) (g x) (h x)
data FL a x = FL [a x]
data FA a b x = FA a (b x)
fieldSIZE :: (Monad m, AdmitAttrSIZE e, AttrValueSIZE v) => v -> WithHTML e m ()
fieldMAXLENGTH :: (Monad m, AdmitAttrMAXLENGTH e, AttrValueMAXLENGTH v) => v -> WithHTML e m ()
fieldVALUE :: (Monad m, AdmitAttrVALUE e, AttrValueVALUE v) => v -> WithHTML e m ()
runWithHook :: CGIOptions -> ([String] -> CGI ()) -> CGI () -> IO ()
docTranslator :: [FreeForm] -> ([String] -> CGI ()) -> [String] -> CGI ()
lastTranslator :: [String] -> CGI ()
class CGIOutput a
data Status = Status {
statusCode :: Int
statusReason :: String
statusContent :: (Maybe (WithHTML () IO ()))
}
newtype Location = Location URL
data FreeForm = FreeForm {
ffName :: String
ffContentType :: String
ffRawContents :: String
}
data FileReference = FileReference {
fileReferenceName :: FilePath
fileReferenceContentType :: String
fileReferenceExternalName :: String
}
newtype Text = Text {
unText :: String
}
newtype NonEmpty = NonEmpty {
unNonEmpty :: String
}
newtype AllDigits = AllDigits {
unAllDigits :: String
}
newtype Phone = Phone {
unPhone :: String
}
newtype EmailAddress = EmailAddress {
unEmailAddress :: String
}
newtype CreditCardNumber = CreditCardNumber {
unCreditCardNumber :: String
}
data CreditCardExp = CreditCardExp {
cceMonth :: Int
cceYear :: Int
}
data CGIOption
= NoPort
| AutoPort
| Port Int
| NoHttps
| AutoHttps
type CGIOptions = [CGIOption]
newtype URL = URL {
unURL :: String
}
makeServlet :: CGI () -> CGIProgram
makeServletWithHook :: ([String] -> CGI ()) -> CGI () -> CGIProgram
standardPage :: (AdmitChildHTML y, Monad m) => String -> WithHTML BODY m a -> WithHTML y m ()
htmlHeader :: (AdmitChildHTML y, Monad m) => String -> WithHTML HTML m a -> WithHTML y m ()
data Style
= NoStyle
| (:=:) String String
| (:^:) Style Style
| Named String
using :: (AdmitAttrSTYLE x, Monad m) => Style -> (WithHTML x m b -> c) -> WithHTML x m b -> c
data FrameLayout
= ROWS
| COLS
data FrameSpacing
= FrameAbsolute Int
| FrameRelative Int
| FramePercent Int
makeFrame :: WithHTML FRAME IO () -> CGI () -> CGI FrameSet
makeFrameset :: FrameLayout -> [(FrameSpacing, CGI FrameSet)] -> CGI FrameSet
framesetPage :: String -> CGI FrameSet -> CGI ()
Basics
data CGI a
Instances
Monad CGI
ask :: WithHTML HTML CGI a -> CGI ()
tell :: CGIOutput a => a -> CGI ()
Terminates script by sending its argument to the browser.
io :: (Read a, Show a) => IO a -> CGI a
Safe embedding of an IO action into the CGI monad.
run :: CGI () -> IO ()

Turns a CGI action into an IO action. Used to turn the main CGI action into the main function of the program. Typical use:

 main = run mainCGI
once :: (Read a, Show a) => CGI a -> CGI a
Brackets a CGI action so that only its result is visible. Improves efficiency by not executing the bracketed action after it has been performed once. Use this for avoiding the buildup of long backlogs.
forever :: CGI () -> CGI ()
Repeats a CGI action without saving its state so that the size of the log remains constant.
htell :: WithHTML HTML IO () -> CGI a
askOffline :: WithHTML HTML CGI a -> (Element -> IO ()) -> CGI ()
Links and Images
data Image
Instances
internalImage
:: FreeFormthe raw image
-> Stringalternative text
-> WithHTML x CGI Image
Reference to internal image.
externalImage
:: URLURL of image
-> Stringalternative text
-> WithHTML x CGI Image
Reference to image by URL.
makeImg :: AdmitChildIMG y => Image -> HTMLField IMG y ()
makeRef :: (AdmitChildA y, Monad m) => String -> WithHTML A m () -> CGI (WithHTML y m ())
makePopupRef :: AdmitChildA y => String -> String -> HTMLField A y ()
makeA :: AdmitChildA y => String -> String -> HTMLField A y ()
backLink :: (AdmitChildA x, Monad m) => HTMLCons A x m ()
hlink :: (AdmitChildA y, Monad m) => URL -> HTMLCons A y m ()
popuplink :: (AdmitChildA y, Monad m) => String -> URL -> HTMLCons A y m ()
restart :: CGI ()
Forms and Widgets
type HTMLField x y a = WithHTML x CGI () -> WithHTML y CGI a
Every input widget maps the content generator for the widget (which may produce HTML elements or attributes) to the content generator of the widget.
Form Creation
makeForm :: AdmitChildFORM y => WithHTML FORM CGI a -> WithHTML y CGI ()
standardQuery :: String -> WithHTML FORM CGI a -> CGI ()
Form Submission
submit :: (AdmitChildINPUT y, InputHandle h) => h INVALID -> (h VALID -> CGI ()) -> HTMLField INVALID y ()
submit0 :: AdmitChildINPUT y => CGI () -> HTMLField INPUT y ()
defaultSubmit :: (AdmitChildINPUT y, InputHandle h) => h INVALID -> (h VALID -> CGI ()) -> HTMLField INPUT y ()
resetField :: AdmitChildINPUT y => HTMLField INPUT y (InputField () INVALID)
activeInputField :: (AdmitChildINPUT y, Reason a, Read a) => (a -> CGI ()) -> HTMLField INPUT y ()
activate :: AdmitChildINPUT y => (a -> CGI ()) -> HTMLField INPUT y (InputField a INVALID) -> HTMLField INPUT y ()
submitx :: AdmitChildINPUT y => DTree INPUT y -> HTMLField INPUT y ()
data DTree x y
Abstract type of decisions trees. These trees provide structured validation.
Instances
dtleaf :: CGI () -> DTree x y
Create a leaf in a decision tree from a CGI action.
dtnode :: InputHandle h => h INVALID -> (h VALID -> DTree x y) -> DTree x y
Create a node in a decision tree. Takes an invalid input field and a continuation. Validates the input field and passes it to the continuation if the validation was successful. The continuation can dispatch on the value of the input field and produces a new decision tree.
Textual Input
inputField :: (AdmitChildINPUT y, Reason a, Read a) => HTMLField INPUT y (InputField a INVALID)
textInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField String INVALID)
passwordInputField :: (AdmitChildINPUT y, Reason a, Read a) => HTMLField INPUT y (InputField a INVALID)
makeTextarea :: AdmitChildTEXTAREA y => String -> HTMLField TEXTAREA y (InputField String INVALID)
Checkbox
checkboxInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField Bool INVALID)
Button
makeButton :: AdmitChildINPUT y => HTMLField INPUT y (InputField Bool INVALID)
data RadioGroup a x
Instances
HasValue RadioGroup
InputHandle (RadioGroup a)
StripHandle (RadioGroup a x) a
radioGroup :: Read a => WithHTML x CGI (RadioGroup a INVALID)
Create a handle for a new radio group. This handle is invisible on the screen!
radioButton :: (AdmitChildINPUT y, Show a) => RadioGroup a INVALID -> a -> HTMLField INPUT y ()
radioError :: AdmitChildIMG x => RadioGroup a INVALID -> WithHTML x CGI ()
Image
imageField :: AdmitChildINPUT y => Image -> HTMLField INPUT y (InputField (Int, Int) INVALID)
Selection Box
selectMultiple :: (AdmitChildSELECT y, Eq a) => (a -> String) -> [a] -> [a] -> (Int, Int) -> HTMLField SELECT y (InputField [a] INVALID)
selectSingle :: (AdmitChildSELECT y, Eq a) => (a -> String) -> Maybe a -> [a] -> HTMLField SELECT y (InputField a INVALID)
selectBounded :: (AdmitChildSELECT y, Enum a, Bounded a, Read a, Show a, Eq a) => Maybe a -> HTMLField SELECT y (InputField a INVALID)
File
fileInputField :: AdmitChildINPUT y => HTMLField INPUT y (InputField FileReference INVALID)
Handle Manipulation
data InputField a x
Instances
HasValue InputField
InputHandle (InputField a)
StripHandle (InputField a x) a
data VALID
Instances
data INVALID
Instances
value :: HasValue i => i a VALID -> a
class InputHandle h
Instances
InputHandle (InputField a)
InputHandle F0
InputHandle a => InputHandle (F1 a)
(InputHandle a, InputHandle b) => InputHandle (F2 a b)
(InputHandle a, InputHandle b, InputHandle c) => InputHandle (F3 a b c)
(InputHandle a, InputHandle b, InputHandle c, InputHandle d) => InputHandle (F4 a b c d)
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e) => InputHandle (F5 a b c d e)
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e, InputHandle f) => InputHandle (F6 a b c d e f)
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e, InputHandle f, InputHandle g) => InputHandle (F7 a b c d e f g)
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e, InputHandle f, InputHandle g, InputHandle h) => InputHandle (F8 a b c d e f g h)
InputHandle a => InputHandle (FL a)
InputHandle b => InputHandle (FA a b)
InputHandle (RadioGroup a)
InputHandle (SelectionGroup a)
data F0 x
Constructors
F0
Instances
InputHandle F0
data F1 a x
Constructors
F1 (a x)
Instances
InputHandle a => InputHandle (F1 a)
data F2 a b x
Constructors
F2 (a x) (b x)
Instances
(InputHandle a, InputHandle b) => InputHandle (F2 a b)
data F3 a b c x
Constructors
F3 (a x) (b x) (c x)
Instances
(InputHandle a, InputHandle b, InputHandle c) => InputHandle (F3 a b c)
data F4 a b c d x
Constructors
F4 (a x) (b x) (c x) (d x)
Instances
(InputHandle a, InputHandle b, InputHandle c, InputHandle d) => InputHandle (F4 a b c d)
data F5 a b c d e x
Constructors
F5 (a x) (b x) (c x) (d x) (e x)
Instances
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e) => InputHandle (F5 a b c d e)
data F6 a b c d e f x
Constructors
F6 (a x) (b x) (c x) (d x) (e x) (f x)
Instances
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e, InputHandle f) => InputHandle (F6 a b c d e f)
data F8 a b c d e f g h x
Constructors
F8 (a x) (b x) (c x) (d x) (e x) (f x) (g x) (h x)
Instances
(InputHandle a, InputHandle b, InputHandle c, InputHandle d, InputHandle e, InputHandle f, InputHandle g, InputHandle h) => InputHandle (F8 a b c d e f g h)
data FL a x
Constructors
FL [a x]
Instances
InputHandle a => InputHandle (FL a)
data FA a b x
Constructors
FA a (b x)
Instances
InputHandle b => InputHandle (FA a b)
Attribute Shortcuts
fieldSIZE :: (Monad m, AdmitAttrSIZE e, AttrValueSIZE v) => v -> WithHTML e m ()
fieldMAXLENGTH :: (Monad m, AdmitAttrMAXLENGTH e, AttrValueMAXLENGTH v) => v -> WithHTML e m ()
fieldVALUE :: (Monad m, AdmitAttrVALUE e, AttrValueVALUE v) => v -> WithHTML e m ()
Advanced
Installing Translators
runWithHook :: CGIOptions -> ([String] -> CGI ()) -> CGI () -> IO ()
Variant of run where an additional argument cgigen specifies an action taken when the script is invoked with a non-empty query string as in script-name?query-string
docTranslator :: [FreeForm] -> ([String] -> CGI ()) -> [String] -> CGI ()
A translator is a function [String] -> CGI (). It takes the query string of the URL (of type [String]) and translates it into a CGI action. docTranslator docs next takes a list of FreeForm documents and a next translator. It tries to select a document by its ffName and falls through to the next translator if no document matches.
lastTranslator :: [String] -> CGI ()
Terminates a sequence of translators.
Outputable Stuff
class CGIOutput a
Instances
CGIOutput a => CGIOutput [a]
CGIOutput ELEMENT_
CGIOutput Char
CGIOutput FileReference
CGIOutput ResponseFileReference
CGIOutput Status
CGIOutput Location
CGIOutput FreeForm
data Status
Constructors
Status
statusCode :: Intstatus code
statusReason :: Stringreason phrase
statusContent :: (Maybe (WithHTML () IO ()))more explanation
Instances
CGIOutput Status
newtype Location
Constructors
Location URLredirection
Instances
CGIOutput Location
data FreeForm
Constructors
FreeForm
ffName :: Stringinternal name
ffContentType :: StringMIME type
ffRawContents :: Stringcontents as octet stream
Instances
CGIOutput FreeForm
data FileReference
Constructors
FileReference
fileReferenceName :: FilePathvalid local filename where this file can be accessed
fileReferenceContentType :: String
fileReferenceExternalName :: String
Instances
Reason FileReference
CGIOutput FileReference
Show FileReference
Read FileReference
Predefined Types for Input Fields
newtype Text
Arbitrary string data. No quotes required.
Constructors
Text
unText :: String
Instances
Read Text
Show Text
Reason Text
newtype NonEmpty
Non-empty strings.
Constructors
NonEmpty
unNonEmpty :: String
Instances
Read NonEmpty
Show NonEmpty
Reason NonEmpty
newtype AllDigits
Non-empty strings of digits.
Constructors
AllDigits
unAllDigits :: String
Instances
Read AllDigits
Show AllDigits
Reason AllDigits
newtype Phone
Phone numbers.
Constructors
Phone
unPhone :: String
Instances
Read Phone
Show Phone
Reason Phone
newtype EmailAddress
Reads an email address according to RFC 2822
Constructors
EmailAddress
unEmailAddress :: String
Instances
Read EmailAddress
Show EmailAddress
Reason EmailAddress
newtype CreditCardNumber
Reads a credit card number and performs Luhn check on it.
Constructors
CreditCardNumber
unCreditCardNumber :: String
Instances
Read CreditCardNumber
Show CreditCardNumber
Reason CreditCardNumber
data CreditCardExp
Reads credit card expiration dates in format .
Constructors
CreditCardExp
cceMonth :: Int
cceYear :: Int
Instances
Read CreditCardExp
Show CreditCardExp
Reason CreditCardExp
Lowlevel Options
data CGIOption
Constructors
NoPortdo not include port number in generated URLs
AutoPortinclude automatically generated port number in generated URLs
Port Intuse this port number in generated URLs
NoHttpsdo not attempt to detect Https
AutoHttpsautodetect Https by checking for port number 443 and env var HTTPS
Instances
Eq CGIOption
type CGIOptions = [CGIOption]
newtype URL
Constructors
URL
unURL :: String
Instances
Read URL
Show URL
Reason URL
Servlets
makeServlet :: CGI () -> CGIProgram
Transform a CGI action into a servlet suitable for running from Marlow's web server.
makeServletWithHook :: ([String] -> CGI ()) -> CGI () -> CGIProgram
Like makeServlet with additional CGI generator as in runWithHook.
HTML and Style
standardPage :: (AdmitChildHTML y, Monad m) => String -> WithHTML BODY m a -> WithHTML y m ()
htmlHeader :: (AdmitChildHTML y, Monad m) => String -> WithHTML HTML m a -> WithHTML y m ()
data Style
First class style elements. Intended for CSS2.
Constructors
NoStyle
(:=:) String Stringprimitive style name :=: value
(:^:) Style Stylecombine two styles
Named Stringreference to style sheet
Instances
Show Style
using
:: (AdmitAttrSTYLE x, Monad m)
=> Style
-> (WithHTML x m b -> c)a field constructor, typically HTMLField
-> WithHTML x m b
-> cstyled version of this constructor
Experimental Stuff
data FrameLayout
Overall layout of a frame set: row-wise or column-wise.
Constructors
ROWS
COLS
Instances
Show FrameLayout
data FrameSpacing
Division of space between elements of a frameset. See http://wp.netscape.com/assist/net_sites/frame_syntax.html
Constructors
FrameAbsolute Intin pixels
FrameRelative Intthe * format
FramePercent Intthe % format
Instances
Show FrameSpacing
makeFrame :: WithHTML FRAME IO () -> CGI () -> CGI FrameSet
makeFrameset :: FrameLayout -> [(FrameSpacing, CGI FrameSet)] -> CGI FrameSet
Create a frameset, given a layout, its spacing, and its subframe(set)s.
framesetPage :: String -> CGI FrameSet -> CGI ()
Required wrapper for pages with frames. Takes a title and a FrameSet generator and displays the page.
Produced by Haddock version 0.5