Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add a Show instance for HashSet #16

Merged
merged 4 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2011
  1. @bos
Commits on Apr 28, 2011
  1. @bos

    Merge with Johan

    bos authored
Commits on Jun 22, 2011
  1. @bos

    Merge

    bos authored
  2. @bos

    Add a Show instance for HashSet

    bos authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +7 −0 Data/HashSet.hs
View
7 Data/HashSet.hs
@@ -97,6 +97,10 @@ instance (Hashable a, Eq a) => Monoid (HashSet a) where
mappend = union
{-# INLINE mappend #-}
+instance (Show a) => Show (HashSet a) where
+ showsPrec d m = showParen (d > 10) $
+ showString "fromList " . shows (toList m)
+
-- | /O(1)/ Construct an empty set.
empty :: HashSet a
empty = HashSet H.empty
@@ -109,6 +113,9 @@ singleton a = HashSet (H.singleton a ())
#endif
-- | /O(n)/ Construct a set containing all elements from both sets.
+--
+-- To obtain good performance, the smaller set must be presented as
+-- the first argument.
union :: (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
union s1 s2 = HashSet $ H.union (asMap s1) (asMap s2)
{-# INLINE union #-}
Something went wrong with that request. Please try again.