user1198582
user1198582

Reputation:

Does my compiler error really have to do with the quasiquote, or is it something more subtle?

I'm following the yesod book example about how to use monadic forms. My getRootR action was taken almost verbatim from the book. I got a compiler error, stripped the quasiquote but still got the error. Below is my error message, the code as it is, followed by what I would like getRootR to look like. Any input as to what the problem might be would be much appreciated.

ghci Rocko.hs

... several "package loading" messages pass until ...

Rocko.hs:67:5:

Couldn't match type `handler'
               with `GGHandler
                       Scheduler
                       Scheduler
                       (Data.Enumerator.Iteratee Data.ByteString.Internal.ByteString IO)'
  `handler' is a rigid type variable bound by
            the type signature for getRootR :: handler RepHtml at Rocko.hs:65:1
Expected type: handler RepHtml
  Actual type: GGHandler
                 Scheduler
                 Scheduler
                 (Data.Enumerator.Iteratee Data.ByteString.Internal.ByteString IO)
                 RepHtml
Expected type: handler RepHtml
  Actual type: GHandler Scheduler Scheduler RepHtml
In the return type of a call of `defaultLayout'
In the expression:
  defaultLayout
    (addHtml
       ((Text.Blaze.Internal.preEscapedText . Data.Text.pack)
          "<p>Result: </p>"))

Failed, modules loaded: JsonParser.

>{-# LANGUAGE OverloadedStrings, TypeFamilies, QuasiQuotes,
         TemplateHaskell, MultiParamTypeClasses #-}
>import Yesod
 import Control.Applicative
 import Control.Monad
 import Data.Text (Text)
 import Data.Time
 import Yesod.Form.Jquery
 import JsonParser

 data Scheduler = Scheduler

 mkYesod "Scheduler" [parseRoutes|
 / RootR GET
 |]

 instance Yesod Scheduler where
    approot _ = ""

 instance RenderMessage Scheduler FormMessage where
    renderMessage _ _ = defaultFormMessage

 instance YesodJquery Scheduler

 data SelectedProduct = MKsp { product :: Text
                             , version :: Text
                             , requestedDate :: Day
                             } deriving Show


 productForm :: Html
             -> Form Scheduler Scheduler (FormResult SelectedProduct, Widget)
 productForm extra = do
    pInfo <- liftIO getUIdata
    let products = Prelude.map productACC $ fst pInfo
        versions = Prelude.map versionsACC $ snd pInfo
        version' = head versions
    (productRes, productView) <- mreq (radioField products) "Placeholder" Nothing
    (versionRes, versionView) <- mreq (selectField version') "Placeholder" Nothing
    (dateRes, dateView) <- mreq (jqueryDayField def
                          { jdsChangeYear = True
                          , jdsYearRange = "2011:2012"
                          }) "Schedule" Nothing
    let selectedRes = MKsp <$> productRes <*> versionRes <*> dateRes
        widget = do
           toWidget [whamlet|
  #{extra}
  <p>
     ^{fvInput productView}
     ^{fvInput versionView}
     ^{fvInput dateView}
     <input type=submit value="aint that some &^*^">
  |]

    return (selectedRes, widget)

 productACC :: ProductNames -> (Text,Text)
 productACC (MKpn pNames) = (pNames,pNames)

 versionsACC :: [ProductVersions] -> [(Text,Text)]
 versionsACC pVersions = Prelude.map vACC' pVersions
                                where vACC' (MKpv pversions') = (pversions', pversions')

 getRootR :: handler RepHtml
 getRootR = do
     ((res, widget), enctype) <- runFormGet productForm
     defaultLayout [whamlet|
 <p>Result:
 |]

 main = return ()
 -- main :: IO ()
 --main = warpDebug 3000 Scheduler `

Here's what I would like getRootR to look like for now

>getRootR :: Handler RepHtml
 getRootR = do
   ((res, widget), enctype) <- runFormGet productForm
   defaultLayout [whamlet|
  <p>Result: #{show res}
  <form enctype=#{enctype}>
      ^{widget}
  |]

Upvotes: 3

Views: 224

Answers (1)

Sjoerd Visscher
Sjoerd Visscher

Reputation: 12000

I guess it is because you have

getRootR :: handler RepHtml

Handler should be with uppercase h.

Upvotes: 4

Related Questions