[web-devel] A trouble with hamlet quasiquoter

Dmitry Vyal akamaus at gmail.com
Fri Feb 24 10:10:33 CET 2012


Greetings,

I'm trying to write a custom Yesod field for displaying a list of words. 
I copied the code from textareaField and played with it. Unfortunately, 
I'm getting a rather strange error message from the compiler. What's I'm 
doing wrong?

data GenTask = GenTask {
   gtWords :: [String],
   gtNumResults :: Int
}

blank :: (Monad m, RenderMessage master FormMessage)
       => (Text -> Either FormMessage a) -> [Text] -> m (Either 
(SomeMessage master) (Maybe a))
blank _ [] = return $ Right Nothing
blank _ ("":_) = return $ Right Nothing
blank f (x:_) = return $ either (Left . SomeMessage) (Right . Just) $ f x

textListField = Field
     { fieldParse = blank $ Right . map T.unpack . T.words
     , fieldView = \theId name theClass val isReq -> addHamlet
         [hamlet|\
<textarea id="#{theId}" name="#{name}" :not (null 
theClass):class="#{T.intercalate " " theClass}" type="text" 
:isReq:required=""> #{either id (T.pack . unwords) val}
|]
}

gtAForm = GenTask
<$> areq textListField "List of words" Nothing
<*> areq intField "Number of results to show" (Just 10)


[1 of 1] Compiling Main             ( src/Web.hs, interpreted )

src/Web.hs:42:9:
     Exception when trying to run compile-time code:
       "\
<textarea id="#{theId}" name="#{name}" :not (null 
theClass):class="#{T.intercalate " " theClass}" type="text" 
:isReq:required=""> #{either id (T.pack . unwords) val}
" (line 2, column 143):
unexpected "("
expecting "}"
       Code: Language.Haskell.TH.Quote.quoteExp
               hamlet
               "\\\n<textarea id=\"#{theId}\" name=\"#{name}\" :not 
(null theClass):class=\"#{T.intercalate \" \" theClass}\" type=\"text\" 
:isReq:required=\"\"> #{either id (T.pack . unwords) val}\n"
Failed, modules loaded: none.





More information about the web-devel mailing list