
On Sun, 21 Sep 2014, Joseph Abrahamson wrote:
The “purely applicative Either” is Either with a new Applicative interface which can no longer take a corresponding Monad interface. I have personally reinvented it over and over although it is perhaps commonly known as Validation:
data Validation e a = Invalid e | Valid a deriving ( Show, Functor, … )
instance Monoid e => Applicative (Validation e) where pure = Valid Invalid e1 <*> Invalid e2 = Invalid (e1 <> e2) Invalid e1 <*> _ = Invalid e1 <*> Invalid e2 = Invalid e2 Valid f <*> Valid a = Valid (f a)
-- No corresponding Monad
It could be perhaps better implemented as a newtype wrapper over Either to facilitate rapid conversion to the more common type.
I would define it as you did above. Left and Right constructors of Either are not very descriptive.
I would like to build a proposal to include Validation in some form in a common package. Despite the misalignment with the name, `transformers` seems like a plausible target, though I fear changes to that package are rarely worth the pain. Suggestions on implementation and target package are welcome. Pending informative feedback, I will try to write a true proposal within 2 weeks.
My first choice would be 'transformers' because I already import this extensively. Second choice would be any other package that is plain Haskell 98 for portability reasons.