Add instance Alternative (Either e)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Add instance Alternative (Either e)

Dannyu NDos
instance Monoid e => Alternative (Either e) where
    empty = left mempty
    Left x <|> Left y = Left (x <> y)
    Left _ <|> y = y
    x <|> _ = x

Leftmost Right is returned for sake of consistence with Semigroup instance.

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Reply | Threaded
Open this post in threaded view
|

Re: Add instance Alternative (Either e)

Herbert Valerio Riedel-3
On Tue, Aug 6, 2019 at 9:40 PM Dannyu NDos <[hidden email]> wrote:
> instance Monoid e => Alternative (Either e) where
>     empty = left mempty
>     Left x <|> Left y = Left (x <> y)
>     Left _ <|> y = y
>     x <|> _ = x
>
> Leftmost Right is returned for sake of consistence with Semigroup instance.

Related: https://ghc.haskell.org/trac/ghc/ticket/9588
_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries