Search code examples
haskellyesod

What's the type of custom Fields containing calls to widgetFile?


If giving fancyTextField an explicit type will fix this problem, which type do I give it? It expects something in the form of Field m Text, but I'm not sure what m to substitute with.

Here's the error message:

Couldn't match type `HandlerSite m0' with `App'
The type variable `m0' is ambiguous
Possible cause: the monomorphism restriction applied to the following:
  fancyTextField :: Field m0 Text
    (bound at Widget/Input/Text.hs:13:1)
Probable fix: give these definition(s) an explicit type signature
Expected type: [Text]
               -> [FileInfo]
               -> m0 (Either (SomeMessage (HandlerSite m0)) (Maybe Text))
  Actual type: [Text]
               -> [FileInfo] -> m0 (Either (SomeMessage App) (Maybe Text))
In the `fieldParse' field of a record
In the expression:
  Field
    {fieldParse = parseHelper $ Right, fieldView = textInput,
     fieldEnctype = UrlEncoded}
In an equation for `fancyTextField':
    fancyTextField
      = Field
          {fieldParse = parseHelper $ Right, fieldView = textInput,
           fieldEnctype = UrlEncoded}

And here's the code:

module Widget.Input.Text where

import Import

-- This is text Field calling the textInput widget below.
fancyTextField = Field {
  fieldParse = parseHelper $ Right,
  fieldView = textInput,
  fieldEnctype = UrlEncoded
}

type FieldWidget =
     Text             -- Id.
  -> Text             -- Name.
  -> [(Text, Text)]   -- Attributes.
  -> Either Text Text -- Value.
  -> Bool             -- Required?
  -> Widget

textInput :: FieldWidget
textInput i name attrs val req = do
  -- The following works:
  -- [whamlet|<div>Test!|]

  -- But the following doesn't!
  $(widgetFile "fancy")

Solution

  • I believe you want to use Handler in place of m.