Proposal: add fromRight and fromLeft to Data.Either
Andreas Abel
abela at chalmers.se
Sat May 21 18:06:50 UTC 2016
Ah, yes, we want fromLeft and fromRight, but with types
fromLeft :: a -> Either a b -> a
fromRight :: b -> Either a b -> b
where the first argument is the "default", like
fromLeft a (Right b) = a
Then you can write
fromLeft impossible e
where `impossible` does a controlled crash of your program. (See
fromMaybe.)
--Andreas
On 21.05.2016 15:16, Edward Kmett wrote:
> Sorry, I meant fromJust.
>
> On Sat, May 21, 2016 at 8:58 AM, David Feuer <david.feuer at gmail.com
> <mailto:david.feuer at gmail.com>> wrote:
>
> No one wants to remove fromMaybe. In fact, it could serve as a
> template for total fromLeft and fromRight:
>
> fromLeft :: b -> (a -> b) -> Either a x -> b
> fromRight :: b -> (a -> b) -> Either x a -> b
>
> On May 21, 2016 8:55 AM, "Edward Kmett" <ekmett at gmail.com
> <mailto:ekmett at gmail.com>> wrote:
>
> I'm personally -1 on this.
>
> A large portion of the community is vehemently against adding
> new partial functions, and they have to share base with the rest
> of us. I'd say more people want to remove fromMaybe, head, tail,
> etc. than want to double down on the pattern at this time.
>
> -Edward
>
> On Fri, May 20, 2016 at 4:08 PM, Anton Felix Lorenzen
> <anfelor at posteo.de <mailto:anfelor at posteo.de>> wrote:
>
> When working with Either,
> I am often missing two simple functions:
> fromRight :: Either a b -> b
> fromLeft :: Either a b -> a
>
> It has been implemented a couple of times:
> http://hayoo.fh-wedel.de/?query=fromRight
>
> But I don't want to depend on yet another library
> for such a basic function.
>
> Could it be added?
>
> Anton
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org <mailto:Libraries at haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org <mailto:Libraries at haskell.org>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
>
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
--
Andreas Abel <>< Du bist der geliebte Mensch.
Department of Computer Science and Engineering
Chalmers and Gothenburg University, Sweden
andreas.abel at gu.se
http://www2.tcs.ifi.lmu.de/~abel/
More information about the Libraries
mailing list