Merge pull request #1795 from TeofilC/monad-aform

yesod-form: Add Monad AForm instance for transformers >=0.6
This commit is contained in:
Michael Snoyman 2023-02-09 08:23:56 +02:00 committed by GitHub
commit 0fa3dbcab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,9 @@
# ChangeLog for yesod-form
## 1.7.4
* Added a `Monad AForm` instance only when `transformers` >= 0.6 [#1795](https://github.com/yesodweb/yesod/pull/1795)
## 1.7.3
* Fixed `radioField` according to Bootstrap 3 docs. [#1783](https://github.com/yesodweb/yesod/pull/1783)

View File

@ -166,6 +166,18 @@ instance Monad m => Applicative (AForm m) where
(a, b, ints', c) <- f mr env ints
(x, y, ints'', z) <- g mr env ints'
return (a <*> x, b . y, ints'', c `mappend` z)
#if MIN_VERSION_transformers(0,6,0)
instance Monad m => Monad (AForm m) where
(AForm f) >>= k = AForm $ \mr env ints -> do
(a, b, ints', c) <- f mr env ints
case a of
FormSuccess r -> do
(x, y, ints'', z) <- unAForm (k r) mr env ints'
return (x, b . y, ints'', c `mappend` z)
FormFailure err -> pure (FormFailure err, b, ints', c)
FormMissing -> pure (FormMissing, b, ints', c)
#endif
instance (Monad m, Monoid a) => Monoid (AForm m a) where
mempty = pure mempty
mappend a b = mappend <$> a <*> b

View File

@ -1,6 +1,6 @@
cabal-version: >= 1.10
name: yesod-form
version: 1.7.3
version: 1.7.4
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>