Skip to content

Relax superclasses for instance Arbitrary Compose #481

Description

@Bodigrim

Currently we define

instance (Arbitrary1 f, Arbitrary1 g, Arbitrary a) => Arbitrary (Compose f g a) where
arbitrary = arbitrary1
shrink = shrink1

That's more restrictive than it can be, it would be nice to relax the constraint to Arbitrary (f (g a)) as in

instance Arbitrary (f (g a)) => Arbitrary (Compose f g a) where 
  arbitrary = Compose <$> arbitrary
  shrink (Compose x) = map Compose (shrink x)

This would bring the approach in line with how base defines all other instances for Compose:

instance Num (f (g a)) => Num (Compose f g a) 	
instance Read (f (g a)) => Read (Compose f g a) 	
instance Fractional (f (g a)) => Fractional (Compose f g a) 	
instance Integral (f (g a)) => Integral (Compose f g a) 	
instance Real (f (g a)) => Real (Compose f g a) 	
instance RealFrac (f (g a)) => RealFrac (Compose f g a) 	
instance Show (f (g a)) => Show (Compose f g a)

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

    Issue actions