简体   繁体   中英

Making custom Yesod Form: Could not deduce (Monad (FormInput m))

I am trying to make multi-file form input. I am using Handling a collection of data in a Yesod Form as a reference.

Here I am trying to make association list of field names to files.

multiFileInput :: Monad m => RenderMessage (HandlerSite m) FormMessage =>
                  [Text] -> FormInput m [(Text, FileInfo)]
multiFileInput = mapM $ secondM (ireq fileField) . (getFieldKey &&& id)

I get error:

Could not deduce (Monad (FormInput m))
    arising from a use of ‘mapM’

But I don't know how to handle this. If I just add this as a constraint I have to propagade this constraint "(Monad (FormInput Handler))" up to a call site, where I don't know how to handle it. FormInput m is an instance of Monad, so I don't understand the issue.

fileInfos <- runInputPost $ multiKeyFileInput "files"

-> No instance for (Monad (FormInput Handler))
    arising from a use of ‘multiKeyFileInput’

I will try to use runRequestBody instead, but it would be nice to understand the problem.

The FormInput data type was supposedly changed from Monad to Applicative , so you have to use traverse , which is an Applicative version of mapM .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM