Reputation: 47
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.
Upvotes: 0
Views: 61
Reputation: 34401
The FormInput
data type was supposedly changed from Monad
to Applicative
, so you have to use traverse
, which is an Applicative
version of mapM
.
Upvotes: 1