system-f / validation

A data-type like Either but with an accumulating Applicative
Other
99 stars 28 forks source link

Why a Semigroup instance? #35

Open srid opened 5 years ago

srid commented 5 years ago

The <> operator on validation values ends up ignoring failures, which seems like something unintended. I discovered this while debugging a validation related bug. Is there a reason Validation is an instance of Semigroup at all?

matthewbauer commented 5 years ago

Here's a good example of where this is confusing:

import Control.Lens
import Data.Validation

failure :: Validation [String] String
failure = _Failure # ["failure"]

success :: Validation [String] String
success = _Success # "success"

main :: IO ()
main = do
  print $ failure <> success
  print $ success <> success
  print $ failure <> failure

I get:

Success "success"
Success "success"
Failure ["failure","failure"]

but I expect to get:

Failure ["failure"]
Success "success"
Failure ["failure","failure"]