Skip to content

Instantly share code, notes, and snippets.

@softmechanics
Created December 26, 2010 08:23
Show Gist options
  • Save softmechanics/755300 to your computer and use it in GitHub Desktop.
Save softmechanics/755300 to your computer and use it in GitHub Desktop.
Yesod: Using GFormMonad without a type signature
{-# LANGUAGE QuasiQuotes, OverloadedStrings, TemplateHaskell, TypeFamilies #-}
import Control.Applicative
import Yesod
import Yesod.Form.Core
data CommentForm = CommentForm
{ user :: String
, comment :: Textarea
, isHtml :: Bool
}
commentForm = do
(user, userField) <- stringField "name:" Nothing
(comment, commentField) <- textareaField "comment:" Nothing
(isHtml , isHtmlField) <- boolField "html?" Nothing
return (
CommentForm <$> user <*> comment <*> isHtml
, [$hamlet|
%p
^fiInput.userField^
%br ^fiInput.commentField^
%br ^fiInput.isHtmlField^
|])
commentForm2 params = CommentForm
<$> stringField "name:" Nothing
<*> textareaField "comment:" Nothing
<*> boolField "html?" Nothing
data Test = Test
mkYesod "Test" [parseRoutes|
/ RootR GET
|]
getRootR = do
((f,w),e) <- runFormMonadGet commentForm
defaultLayout [$hamlet|
%form!method=GET
^w^
%input!type=submit
|]
instance Yesod Test where approot _ = ""
main = basicHandler 3000 Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment