aelve / haskell-issues

An unofficial issue tracker for all things Haskell-related
18 stars 0 forks source link

basic Either combinators should be in Data.Either #49

Open mstksg opened 7 years ago

mstksg commented 7 years ago

There are a lot of useful combinators for Either in the either package http://hackage.haskell.org/package/either-4.4.1.1/docs/Data-Either-Combinators.html but they really should be in Data.Either.

leftToMaybe/rightToMaybe are really the same level of importance as listToMaybe. swapEither is just as ubiquitous as swap. Also maybeToLeft/maybeToRight might as well be there too, matching maybeToList (with an extra parameter). I've re-written some variety of maybeToLeft and maybeToRight so many times I can hardly count >.<

Gurkenglas commented 7 years ago

swap actually sounds like it ought to be generalized into Data.Bifunctor, but that's not possible just by the class definition. Do all instances have that possibility in common?

neongreen commented 7 years ago

Do all instances have that possibility in common?

Definitely not. E.g. Const is a bifunctor, but you can't write Const a b -> Const b a.

neongreen commented 7 years ago

@mstksg I found 9 uses of leftToMaybe on Github (not counting occurrences in various preludes) and about 55 uses of rightToMaybe. This said, they are still used about 5–10 times less often than fromLeft and fromRight (which aren't in base yet but will be added in next release). Personally I don't feel they're particularly useful (and I think I've never used them myself); this makes me hardly a good candidate for “officially” proposing them (as I wouldn't be able to defend their inclusion convincingly). However, I'll keep this issue open in case somebody else feels more enthusiastic about them.

mstksg commented 7 years ago

I doubt you'd find a bunch of rightToMaybe, because --

  1. I've always seen it used by other names, like censor, or eitherToMaybe -- there's no universally agreed name
  2. It's short enough that people usually just write out either (const Nothing) Just or something else -- i've seen files where people use it several times in the same file, or just defined a local alias.

I've had to write Either e a -> Maybe a in many different situations, but mostly when writing a big Maybe do block :)