From 06fd5df1376c007ae327610f27e67ea15099e71d Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 7 Feb 2023 10:48:42 +0000 Subject: [PATCH 1/2] yesod-form: Add Monad AForm instance for transformers >=0.6 This is required in order to have a MonadTrans instance --- yesod-form/Yesod/Form/Types.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/yesod-form/Yesod/Form/Types.hs b/yesod-form/Yesod/Form/Types.hs index df13ab32..994ae3ca 100644 --- a/yesod-form/Yesod/Form/Types.hs +++ b/yesod-form/Yesod/Form/Types.hs @@ -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 From a6e420b42f52836263f9c9e6fc4e7dd1c67dddeb Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Tue, 7 Feb 2023 10:51:00 +0000 Subject: [PATCH 2/2] yesod-form: bump version and add changelog message for #1795 --- yesod-form/ChangeLog.md | 4 ++++ yesod-form/yesod-form.cabal | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/yesod-form/ChangeLog.md b/yesod-form/ChangeLog.md index bfa5671e..fd6f0c87 100644 --- a/yesod-form/ChangeLog.md +++ b/yesod-form/ChangeLog.md @@ -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) diff --git a/yesod-form/yesod-form.cabal b/yesod-form/yesod-form.cabal index 7c881b70..ee4adb7c 100644 --- a/yesod-form/yesod-form.cabal +++ b/yesod-form/yesod-form.cabal @@ -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