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

Alt and left-distribution #19

Open
bitemyapp opened this issue Nov 6, 2017 · 2 comments
Open

Alt and left-distribution #19

bitemyapp opened this issue Nov 6, 2017 · 2 comments

Comments

@bitemyapp
Copy link

Greetings from https://github.com/bitemyapp/hedgehog-checkers

Two laws are mentioned for Alt, is there a reason checkers only validates the associativity and not left-distribution?

Cf. https://hackage.haskell.org/package/semigroupoids-5.2.1/docs/Data-Functor-Alt.html#t:Alt

<!> is associative:             (a <!> b) <!> c = a <!> (b <!> c)
<$> left-distributes over <!>:  f <$> (a <!> b) = (f <$> a) <!> (f <$> b)

And

-- | Check Alt Semigroup law
alt :: forall f a. ( Alt f, Arbitrary a, Arbitrary (f a)
                   , EqProp (f a), Show (f a)) =>
       f a -> TestBatch
alt = const ( "Alt laws"
            , [ ("associativity", isAssoc ((<!>) :: Binop (f a))) ] )

Is it like Functor distribution being derivable from identity or is it missing?

/cc @gwils

@gwils
Copy link
Contributor

gwils commented Nov 6, 2017

It's missing. I can't tell if it follows from other laws, but I suspect that it might, particularly the associativity law and the fmap id = id law. It's hard to do much nasty with a lawful functor. I have no proof of this.

If this test is added for Alt, is it added for Alternative too? I would think Alternative should satisfy all the properties Alt should. But this law is not mentioned in the Alternative docs. So what happens?

@bitemyapp
Copy link
Author

It's missing. I can't tell if it follows from other laws, but I suspect that it might, particularly the associativity law and the fmap id = id law. It's hard to do much nasty with a lawful functor. I have no proof of this.

Worth bugging Ed maybe?

If this test is added for Alt, is it added for Alternative too? I would think Alternative should satisfy all the properties Alt should. But this law is not mentioned in the Alternative docs. So what happens?

I think I'd want to test that one empirically. Could make a separate test that pulls in a bunch of packages and checks the law for a bunch of types. Possibly by making something that uses TH to gin it up.

Not suggesting you necessarily you do that here for checkers, but I'd like to know how the existing ecosystem behaves WRT the law and if there are prominent or frequent violations I'd want to dig in and understand why before I start enforcing it above and beyond what Alternative is conventionally understood to require.

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

No branches or pull requests

2 participants