leftToMaybe/rightToMaybe
Henning Thielemann
lemming at henning-thielemann.de
Thu Aug 8 16:26:17 CEST 2013
On Thu, 8 Aug 2013, Erik Hesselink wrote:
> On Thu, Aug 8, 2013 at 1:09 PM, Henning Thielemann <lemming at henning-thielemann.de> wrote:
>>
>> On Thu, 8 Aug 2013, David Luposchainsky wrote:
>>
>>> On 2013-08-07 19:13, Erik Hesselink wrote:
>>>>>
>>>>> mapEither :: (l -> l') -> (r -> r') -> Either l r -> Either l' r'
>>>>> mapEither fl fr = either (Left . fl) (Right . fr)
>>>>
>>>> This function is hidden in Control.Arrow as (+++).
>>>
>>> I didn't know about those functions, and it seems everything I wanted is
>>> in there somewhere. However, I'm not sure what to think of
>>> Control.Arrow, I've always (ab)used it as an extended Data.Tuple, and as
>>> of today probably for its Either API functions.
>>
>> For me using the arrow functions as Data.Tuple and Data.Either utility
>> functions is abuse. Control.Arrow is meant to generalize (->). If you call
>> maybeLeft and MaybeRight this is certainly not your intention.
>
> But the point of generalized functions is to use them in a specialized
> context, right?
I think the primary goal is to use them to write generic functions.
> You can generalize mapEither in multiple ways: you can generalize (->),
> or you can generalize Either (getting bimap from the bifunctors
> package). I don't get why it's wrong to specialize the Arrow to (->) and
> use the functions on Eithers or tuples.
Why should someone care about Arrows if he only wants to process Either?
> I do agree that they're hard to find.
For me this is a hint that there is something wrong.
If I want to have a function mapEither and do not find it in Data.Either,
I might have the idea that it is subsumed by a more general function
somewhere else. In this case I would certainly think about a
generalization of Either, but not of (->).
More information about the Libraries
mailing list