Created
January 5, 2011 00:30
-
-
Save mightybyte/765719 to your computer and use it in GitHub Desktop.
Working on HasFormlet type class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeSynonymInstances #-} | |
module Text.Digestive.Blaze.Instances where | |
import Data.Maybe | |
import Text.Digestive.Blaze.Html5 (inputText, inputCheckBox, inputTextRead) | |
import Text.Digestive.Forms (FormInput) | |
import Text.Digestive.Types (Form) | |
class HasFormlet a where | |
formlet :: (Monad m, Functor m, FormInput i f) => e -> Maybe a -> Form m i e v a | |
instance HasFormlet String where | |
formlet _ d = inputText d | |
instance HasFormlet Bool where | |
formlet _ d = inputCheckBox $ fromMaybe False d | |
instance HasFormlet Int where | |
formlet = inputTextRead | |
instance HasFormlet Float where | |
formlet = inputTextRead | |
instance HasFormlet Double where | |
formlet = inputTextRead | |
{- | |
This code gets five errors like the following: | |
Foo.hs:13:18: | |
Couldn't match expected type `v' | |
against inferred type `Text.Digestive.Forms.Html.FormHtml | |
Text.Blaze.Internal.Html' | |
`v' is a rigid type variable bound by | |
the type signature for `formlet' at Foo.hs:10:81 | |
Expected type: Form m i e v String | |
Inferred type: Form | |
m i e Text.Digestive.Blaze.Html5.BlazeFormHtml String | |
In the expression: inputText d | |
In the definition of `formlet': formlet _ d = inputText d | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment