[web-devel] problem with radioField from yesod.Forms

Michael Litchard michael at schmong.org
Tue Jun 7 01:30:33 CEST 2011


I am working from the widget example from the Yesod web site.
I was able to display a column of check boxes, and am able to generate
a [Bool], which is enough for now, as far as the check boxes go. Now,
I would like a column of radioFields.
I will worry about the CSS and Ajax stuff later. The problem is that
radioField uses a slightly different type. I admit I don't understand
some of these types, but I can exploit my pattern recognition skills
well enough. Below is my last attempt.

The type for radioField is
radioField :: (Eq x, IsForm f, FormType f ~ x) => [(x, Text)] ->
FormFieldSettings -> Maybe x -> f

The type for boolField is
boolField :: (IsForm f, FormType f ~ Bool) => FormFieldSettings ->
Maybe Bool -> f

It's the [(x,Text)] that is tricking me. I suspect the problem may be
me not understanding the Applicative style well enough.
Could someone offer some feedback to send me on the right track?


> handleFormR = do
>     (res, form, enctype, nonce) <- runFormPost $ fieldsToTable $ (,,,,,,,,)
>         <$> boolField "Server One" Nothing
>         <*> boolField "Server Two" Nothing
>         <*> boolField "Server Three" Nothing
>         <*> boolField "Server Four" Nothing
>         <*> boolField "Server Five" Nothing
>         <*> boolField "Server Six" Nothing
>         <*> boolField "Server Seven" Nothing
>         <*> boolField "Server Eight" Nothing
>         <*> radioField [(1, "Test 1"), (2, "Test 2")] "Pick a Test" Nothing

mlitchard at apotheosis:~/playground/yesod-examples-0.8.0.1/src$
runhaskell nwidgets.lhs

nwidgets.lhs:46:7:
    The last statement in a 'do' construct must be an expression:
    (res, form, enctype, nonce) <- runFormPost $ fieldsToTable
                               $ (,,,,,,,,)
                             <$>
                               boolField "Server One" Nothing
                           <*>
                             boolField "Server Two" Nothing
                         <*>
                           boolField "Server Three" Nothing
                       <*>
                         boolField "Server Four" Nothing
                     <*>
                       boolField "Server Five" Nothing
                   <*>
                     boolField "Server Six" Nothing
                 <*>
                   boolField "Server Seven" Nothing
               <*>
                 boolField "Server Eight" Nothing
             <*>
               radioField [(1, "Test 1"), (2, "Test 2")] "Test 1" Nothing



More information about the web-devel mailing list