LGTM, thanks.

On Thu, Feb 6, 2014 at 10:52 AM, Klaus Aehlig <[email protected]> wrote:

> From: Petr Pudlak <[email protected]>
>
> This allows to use Alternative specific combinators, namely `optional`.
>
> Signed-off-by: Petr Pudlak <[email protected]>
> Reviewed-by: Klaus Aehlig <[email protected]>
>
> Cherry-pick of 78209a84b0f6be27fd381ac2
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/BasicTypes.hs | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/src/Ganeti/BasicTypes.hs b/src/Ganeti/BasicTypes.hs
> index 73b11fb..546cddb 100644
> --- a/src/Ganeti/BasicTypes.hs
> +++ b/src/Ganeti/BasicTypes.hs
> @@ -112,6 +112,10 @@ instance Applicative (GenericResult a) where
>    _       <*> (Bad x) = Bad x
>    (Ok f)  <*> (Ok x)  = Ok $ f x
>
> +instance (FromString a, Monoid a) => Alternative (GenericResult a) where
> +  empty = mzero
> +  (<|>) = mplus
> +
>  -- | This is a monad transformation for Result. It's implementation is
>  -- based on the implementations of MaybeT and ErrorT.
>  newtype ResultT a m b = ResultT {runResultT :: m (GenericResult a b)}
> @@ -157,6 +161,10 @@ instance (Monad m, FromString a, Monoid a) =>
> MonadPlus (ResultT a m) where
>    mplus x y = elimResultT combine return x
>      where combine x' = ResultT $ liftM (mplus (Bad x')) (runResultT y)
>
> +instance (Monad m, FromString a, Monoid a) => Alternative (ResultT a m)
> where
> +  empty = mzero
> +  (<|>) = mplus
> +
>  -- | Lift a `Result` value to a `ResultT`.
>  resultT :: Monad m => GenericResult a b -> ResultT a m b
>  resultT = ResultT . return
> --
> 1.9.0.rc1.175.g0b1dcb5
>
>

Reply via email to