3 ms·
This pattern is totally embedded into the non-monadic applicative Either sometimes called Validation data Validation e a = Collect e | Value
by tel 12y ago
This pattern is totally embedded into the non-monadic applicative Either sometimes called Validation
data Validation e a
= Collect e
| Value a
deriving Functor
instance Monoid e => Applicative (Validation e) where
pure a = Value a
Collect le <*> Collect re = Collect (le <> re)
Collect e <*> _ = Collect e
_ <*> Collect e = Collect e
Value f <*> Value a = Value (f a)
There is no monad instance for this which lets us scoot forward through a computation and and all of the errors at once.
- HolyHaddock 12y agoThis is worth understanding, and works out a lot better in practice than having to pass in ad-hoc collection builders as equally ignorable "out-params" or exceptions.