Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why a Semigroup instance? #35

Open
srid opened this issue Apr 12, 2019 · 1 comment · May be fixed by #39
Open

Why a Semigroup instance? #35

srid opened this issue Apr 12, 2019 · 1 comment · May be fixed by #39

Comments

@srid
Copy link

srid commented Apr 12, 2019

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
Copy link

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"]

matthewbauer added a commit to matthewbauer/validation that referenced this issue Jun 11, 2019
Previously, a <> b would give success if either a or b were a success!
This should not happen when doing validation. We want any errors to be
propagated.

Fixes system-f#35
matthewbauer added a commit to matthewbauer/validation that referenced this issue Jun 11, 2019
Previously, a <> b would give success if either a or b were a success!
This should not happen when doing validation. We want any errors to be
propagated.

Fixes system-f#35
@matthewbauer matthewbauer linked a pull request Jun 11, 2019 that will close this issue
matthewbauer added a commit to matthewbauer/validation that referenced this issue Jun 11, 2019
Previously, a <> b would give success if either a or b were a success!
This should not happen when doing validation. We want any errors to be
propagated.

Fixes system-f#35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants