Proposal: add fromRight and fromLeft to Data.Either

Dan Doel dan.doel at gmail.com
Sat May 21 18:42:58 UTC 2016


I would add (as I probably did last time something like this came up)
that it's difficult to get excited about all these functions named by
a systematic grammar, when we know _today_ how to just implement that
grammar as a library of composable pieces. And it has been implemented
in lens (and possibly other libraries that are subsets of lens).

Then you can have `is`, `over` (like map), `from` (take your pick on
whether it's partial or with-default), `foldOf`, `traverseOf`, ...,
and `_Left`, `_Right`, `_Just`, `_Nothing` (not all of these
correspond to lens; just you could define them). These building blocks
make all these functions definable, with almost exactly the names
they'd be given as one-off functions in several modules. But of
course, they also compose in more interesting ways, too. You can have
`from (_Left . _Just)`, but we will never be adding a
`fromLeftAndJust` function to base.

I don't really expect (or hope for) base to start pulling in big
chunks of lens. And maybe it makes sense for all of these to be in
base just for uniformity. But it also seems like people could just be
using something better.

-- Dan


On Sat, May 21, 2016 at 8:55 AM, Edward Kmett <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>
> 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
>> 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
>


More information about the Libraries mailing list