Need help with types

30 views
Skip to first unread message

Michael Walton

unread,
Jun 10, 2013, 3:01:37 PM6/10/13
to yeso...@googlegroups.com
Hi Google group,
I'm having trouble understanding how to do something. Please Bear with me here.

I'm defining at data type as follows (this example is taken from my code. Not all of the fields are actually used):

data QFieldSpec m a = QFieldSpec {
     maxFieldLength :: Int
   , formField :: Field m a
   , validators :: [Validator a]
   , toDBVal :: a -> PersistValue
   , columnHeader ::  Text }

Thereupon I add an actual instance of QFieldSpec as follows

studentNumSpec :: (Monad m, RenderMessage (HandlerSite m) FormMessage) => QFieldSpec m Text

studentNumSpec = QFieldSpec {
      maxFieldLength = 8
    , formField = textField
    , validators = []
    , toDBVal = \x -> PersistText x
    , columnHeader = "ID" }


So far so good but when I try to use

myForm =  areq (formField studentNumSpec) idLabel Nothing
 where
   idLabel = (fromString . unpack . columnHeader) studentNumSpec

I get the following complaint about types (which I don't know how to resolve)

    No instance for (RenderMessage (HandlerSite m0) FormMessage)
      arising from a use of `studentNumSpec'
    Possible fix:
      add an instance declaration for
      (RenderMessage (HandlerSite m0) FormMessage)
    In the first argument of `fromString
                              . unpack . columnHeader', namely
      `studentNumSpec'
    In the expression:
      (fromString . unpack . columnHeader) studentNumSpec
    In an equation for `idLabel':
        idLabel = (fromString . unpack . columnHeader) studentNumSpec

Your help will be appreciated.

Thanks,
    Mike W.






Michael Snoyman

unread,
Jun 11, 2013, 5:32:33 AM6/11/13
to yeso...@googlegroups.com
It should be sufficient to just put a type signature on myForm.









--
You received this message because you are subscribed to the Google Groups "Yesod Web Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yesodweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michael Walton

unread,
Jun 11, 2013, 11:05:36 AM6/11/13
to yeso...@googlegroups.com, mic...@snoyman.com
Hi Michael Snoyman,

If its simply a matter if adding the right signature to myForm,
then I have no idea what signature to add.
I added the type
myForm :: (MonadHandler m, RenderMessage (HandlerSite m) FormMessage) =>
                        AForm m Text),
but it's not working.

      Thanks,
    Mike W.

Michael Snoyman

unread,
Jun 11, 2013, 11:07:31 AM6/11/13
to yeso...@googlegroups.com
Try Form Text.

Michael Walton

unread,
Jun 11, 2013, 11:32:44 AM6/11/13
to yeso...@googlegroups.com, mic...@snoyman.com
Hi Michael,

For Text is definitely the wrong
type. If I try that I get
  Couldn't match expected type `Form Text'
                with actual type `AForm m0 a0'
    In the return type of a call of `areq'
    Probable cause: `areq' is applied to too many arguments
    In the expression: areq (formField studentNumSpec) "test" Nothing
    In an equation for `myForm':
        myForm = areq (formField studentNumSpec) "test" Nothing

Thanks,
    Mike W.
Reply all
Reply to author
Forward
0 new messages