leftToMaybe/rightToMaybe
Sturdy, Ian
sturdyi12 at mail.wlu.edu
Thu Aug 8 17:28:51 CEST 2013
> I think the primary goal is to use them to write generic functions.
Would you avoid using mapM_ to sequence a list of IO operations, since it is using a generalized function in a specialized context? I take the idea of the generalized functions as being abstraction, allowing use of a common nomenclature across applications., as having context-specific names for specializations adds to what the programmer must remember to very little end. Where a specific type is needed for clarity or performance, I would prefer a general function and a local type signature rather than forcing a reader to remember yet another function.
> 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 (->).
A fair point, I think; when I first started in Haskell I spent a while rewriting utilities from Control.Arrow because I never thought to look there. But the problem, as I see it, is of documentation, not of use; these are perfectly valid functions for the purpose, just hard to find if you do not already know to look there. (Although that said, Bifunctor does seem the more intuitive generalization here, and the more likely to survive a type change.)
________________________________________
From: Libraries [libraries-bounces at haskell.org] on behalf of Henning Thielemann [lemming at henning-thielemann.de]
Sent: Thursday, August 08, 2013 10:26 AM
To: Erik Hesselink
Cc: libraries
Subject: Re: leftToMaybe/rightToMaybe
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 (->).
_______________________________________________
Libraries mailing list
Libraries at haskell.org
http://www.haskell.org/mailman/listinfo/libraries
More information about the Libraries
mailing list