haskell-checkers/checkers

Alt and left-distribution

Opened this issue · 2 comments

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 commented

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?

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.