Skip to content

less cpp noise in properties using type synonyms #84

Open
@chessai

Description

@chessai
Collaborator

instead of:

prop1 :: forall proxy f.
#if HAVE_QUANTIFIED_CONSTRAINTS
(blah)
#else 
(blah1)
#endif 
  => proxy f -> Property
...

prop1 :: forall proxy f.
#if HAVE_QUANTIFIED_CONSTRAINTS
(blah)
#else 
(blah1)
#endif 
  => proxy f -> Property

we can have, using Bifunctor as an example, the following:

type BifunctorProp f =
  ( Bifunctor f
#if HAVE_QUANTIFIED_CONSTRAINTS
  , forall x y. (Eq x, Eq y) => Eq (f x y)
  , forall x y. (Show x, Show y) => Show (f x y)
  , forall x y. (Arbitrary x, Arbitrary y) => Arbitrary (f x y) 
#else 
  , Eq2 f
  , Show2 f
  , Arbitrary2 f
#endif 
  ) => proxy f -> Property

prop1 :: forall f. BifunctorProp f
prop2 :: forall f. BifunctorProp f
...
prop3million :: forall f. BifunctorProp f

this would help reduce at least some of the noise, and wouldn't be visible externally, since it only affects the internal properties (ie not the user-facing functions of type Proxy a -> Laws)

Activity

chessai

chessai commented on Aug 8, 2019

@chessai
CollaboratorAuthor

this requires constraintkinds. do those work in 7.4? a comment from ekmett in the documentation for the constraints package seems to indicate that they do not.

andrewthad

andrewthad commented on Aug 8, 2019

@andrewthad
Owner

I think this is a good idea. Even without ConstraintKinds:

class 
  ( Bifunctor f
#if HAVE_QUANTIFIED_CONSTRAINTS
  , forall x y. (Eq x, Eq y) => Eq (f x y)
  , forall x y. (Show x, Show y) => Show (f x y)
  , forall x y. (Arbitrary x, Arbitrary y) => Arbitrary (f x y) 
#else 
  , Eq2 f
  , Show2 f
  , Arbitrary2 f
#endif
  ) => TestableBifunctor f

instance 
  ( Bifunctor f
#if HAVE_QUANTIFIED_CONSTRAINTS
  , forall x y. (Eq x, Eq y) => Eq (f x y)
  , forall x y. (Show x, Show y) => Show (f x y)
  , forall x y. (Arbitrary x, Arbitrary y) => Arbitrary (f x y) 
#else 
  , Eq2 f
  , Show2 f
  , Arbitrary2 f
#endif
  ) => TestableBifunctor f

prop1 :: forall f. TestableBifunctor f => proxy f -> Property
prop2 :: forall f. TestableBifunctor f => proxy f -> Property

In the values exposed to the end user, we would still want to make sure that we write out the full signature.

chessai

chessai commented on Aug 8, 2019

@chessai
CollaboratorAuthor

seems a waste to introduce a new class. pollution. i would rather just wait until we don't have to support 7.4, since 7.6 is when ConstraintKinds don't crash GHC.

andrewthad

andrewthad commented on Aug 8, 2019

@andrewthad
Owner

The class wouldn't be visible to users, but regardless I'm fine with waiting until primitive drops support for GHC 7.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @andrewthad@chessai

        Issue actions

          less cpp noise in properties using type synonyms · Issue #84 · andrewthad/quickcheck-classes