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

Documentation warning about the instances for Arbitrary (Set a) and friends being over the abstract set #379

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions examples/Set.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ instance (Ord a, Arbitrary a) => Arbitrary (Set a) where
shrink t@(Node x s1 s2) = [ s1, s2 ]
++ [ t' | x' <- shrink x, let t' = Node x' s1 s2, invariant t' ]

-- instance (Ord a, ShrinkSub a) => ShrinkSub (Set a)

--------------------------------------------------------------------------
-- properties

Expand Down
8 changes: 8 additions & 0 deletions src/Test/QuickCheck/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -852,27 +852,35 @@ instance Arbitrary CDouble where
shrink = shrinkDecimal

-- Arbitrary instances for container types
-- | WARNING: This instance aims to give a good representation of @Set a@
-- as sets but does not aim to provide a varied distribution over the
-- underlying representation.
instance (Ord a, Arbitrary a) => Arbitrary (Set.Set a) where
arbitrary = fmap Set.fromList arbitrary
shrink = map Set.fromList . shrink . Set.toList
instance (Ord k, Arbitrary k) => Arbitrary1 (Map.Map k) where
liftArbitrary = fmap Map.fromList . liftArbitrary . liftArbitrary
liftShrink shr = map Map.fromList . liftShrink (liftShrink shr) . Map.toList
-- | WARNING: The same warning as for @Arbitrary (Set a)@ applies here.
instance (Ord k, Arbitrary k, Arbitrary v) => Arbitrary (Map.Map k v) where
arbitrary = arbitrary1
shrink = shrink1
-- | WARNING: The same warning as for @Arbitrary (Set a)@ applies here.
instance Arbitrary IntSet.IntSet where
arbitrary = fmap IntSet.fromList arbitrary
shrink = map IntSet.fromList . shrink . IntSet.toList
-- | WARNING: The same warning as for @Arbitrary (Set a)@ applies here.
instance Arbitrary1 IntMap.IntMap where
liftArbitrary = fmap IntMap.fromList . liftArbitrary . liftArbitrary
liftShrink shr = map IntMap.fromList . liftShrink (liftShrink shr) . IntMap.toList
-- | WARNING: The same warning as for @Arbitrary (Set a)@ applies here.
instance Arbitrary a => Arbitrary (IntMap.IntMap a) where
arbitrary = arbitrary1
shrink = shrink1
instance Arbitrary1 Sequence.Seq where
liftArbitrary = fmap Sequence.fromList . liftArbitrary
liftShrink shr = map Sequence.fromList . liftShrink shr . toList
-- | WARNING: The same warning as for @Arbitrary (Set a)@ applies here.
instance Arbitrary a => Arbitrary (Sequence.Seq a) where
arbitrary = arbitrary1
shrink = shrink1
Expand Down
Loading