proposal #4095: add Applicative instance for Either

Iavor Diatchki iavor.diatchki at gmail.com
Tue Jun 1 16:42:40 EDT 2010


Oh, I think that Either has its uses.  For example, a convenient
function that I use every now and then is:
mapEither :: (a -> Either b c) -> [a] -> ([b],[c])
It is kind of like "mapMaybe" and also like "partition".

The benefit of omitting some instances is that when programmers find
them lacking, they might consider an alternative way to achieve their
goal.  In the case of Monad and Either, my feeling is that an
alternative would almost always lead to code which is easier to
understand.  Yitzchak's example illustrates just that.

daysInMonth :: Int -> Int -> Int
daysInMonth month year
  | month == 2 = if isLeap year then 29 else 28
  | month `elem` [4,6,9,11] = 30
  | otherwise = 31

-Iavor

On Tue, Jun 1, 2010 at 8:06 AM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> On Mon, May 31, 2010 at 10:18:11AM -0700, Iavor Diatchki wrote:
>> Are there any uses of this instance that are not related to error
>> handing?  If not, I would propose that we avoid prolonging the
>> confusing use of "Either" for error handling and define a separate
>> type with properly labelled constructors, to be used as "Maybe" but
>> with multiple reasons for failure.
>
> We could do that, but Either would still be there, and the question of
> what instances it should have would remain.  Would it really help to
> withold the obvious instances?
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>


More information about the Libraries mailing list