Skip to content

Commit

Permalink
yesod-form: Add Monad AForm instance for transformers >=0.6
Browse files Browse the repository at this point in the history
This is required in order to have a MonadTrans instance
  • Loading branch information
TeofilC committed Feb 7, 2023
1 parent 3d65a3b commit 17271a7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions yesod-form/Yesod/Form/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17271a7

Please sign in to comment.