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

Monoid instance doesn't obey the concatenation law #23

Closed
wants to merge 1 commit into from

Conversation

rszczers
Copy link

@rszczers rszczers commented Nov 28, 2019

I've played around with hedgehog-classes and your library in hope to solve #5. I guess I found a minor bug with mconcat: the monoid instance didn't obey the concatenation law (i.e. mconcat ≡ foldr mappend mempty). Consecutively, there were also problems with associativity and right identity monad laws; here's relevant part of test log:

Monoid: Concatenation   ✗ <interactive> failed 
    after 41 tests and 47 shrinks.
  
    forAll0 =
      [ Slist { sList = [ 0 ] , sSize = Size 1 }
      , Slist { sList = [ 1 ] , sSize = Size 1 }
      ]
  
    ━━━ Context ━━━
    When testing the Concatenation law(†), for the Monoid typeclass, the following test failed: 
    
    mconcat as ≡ foldr mappend mempty as, where
      as = [Slist {sList = [0], sSize = Size 1},Slist {sList = [1], sSize = Size 1}]
      mempty = Slist {sList = [], sSize = Size 0}
      
    
    The reduced test is: 
      Slist {sList = [1,0], sSize = Size 2} ≡ Slist {sList = [0,1], sSize = Size 2}
    
    The law in question: 
      (†) Concatenation Law: mconcat ≡ foldr mappend mempty

So mconcat concatenated lists in a wrong order, I guess. I flipped just here (xL ++ l, s + xS) to (l ++ xL, s + xS) and now all tests are passing fine :-)

Copy link
Contributor

@hint-man hint-man bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no place for me here... I will choose the truth I like.

Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@vrom911
Copy link
Member

vrom911 commented Nov 30, 2019

Unfortunately, due to the usage of the hedgehog-classes library, I can't merge this to the project, as I'd like to support three latest major GHC versions, however hedgehog-classes limits this intentionally.

I really appreciate your help, but closing the PR and will implement this shortly by hands.

@vrom911 vrom911 closed this Nov 30, 2019
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 this pull request may close these issues.

2 participants