Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Generic Instances for HashMap and HashSet #54

Open
wants to merge 3 commits into from

3 participants

@2piix

Used GHC's "DeriveGeneric" extension to derive Generic instances for HashSets and HashMaps.

@jaspervdj jaspervdj commented on the diff
unordered-containers.cabal
@@ -39,6 +39,7 @@ library
build-depends:
base >= 4 && < 5,
deepseq >= 1.1,
+ ghc-prim >= 0.2,

@2piix, why is this dependency necessary?

@tibbe Owner
tibbe added a note

GHC.Generics is exported by base so it shouldn't be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This was referenced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2012
  1. @2piix

    Update Data/HashSet.hs

    2piix authored
  2. @2piix

    Update Data/HashMap/Base.hs

    2piix authored
Commits on Dec 19, 2012
  1. Generic instances for HashMaps and HashSets

    Alexander Solla authored
This page is out of date. Refresh to see the latest.
View
9 Data/HashMap/Base.hs
@@ -1,6 +1,10 @@
{-# LANGUAGE BangPatterns, CPP, DeriveDataTypeable, MagicHash #-}
{-# OPTIONS_GHC -fno-full-laziness -funbox-strict-fields #-}
+#if defined(__GLASGOW_HASKELL__)
+{-# LANGUAGE DeriveGeneric #-}
+#endif
+
module Data.HashMap.Base
(
HashMap(..)
@@ -97,6 +101,7 @@ import Data.Typeable (Typeable)
#if defined(__GLASGOW_HASKELL__)
import Data.Data hiding (Typeable)
import GHC.Exts ((==#), build, reallyUnsafePtrEquality#)
+import GHC.Generics (Generic)
#endif
------------------------------------------------------------------------
@@ -122,7 +127,11 @@ data HashMap k v
| Leaf !Hash !(Leaf k v)
| Full !(A.Array (HashMap k v))
| Collision !Hash !(A.Array (Leaf k v))
+#if defined(__GLASGOW_HASKELL__)
+ deriving (Generic, Typeable)
+#else
deriving (Typeable)
+#endif
instance (NFData k, NFData v) => NFData (HashMap k v) where
rnf Empty = ()
View
9 Data/HashSet.hs
@@ -1,5 +1,9 @@
{-# LANGUAGE CPP, DeriveDataTypeable #-}
+#if defined(__GLASGOW_HASKELL__)
+{-# LANGUAGE DeriveGeneric #-}
+#endif
+
------------------------------------------------------------------------
-- |
-- Module : Data.HashSet
@@ -72,12 +76,17 @@ import Data.Typeable (Typeable)
#if defined(__GLASGOW_HASKELL__)
import Data.Data hiding (Typeable)
import GHC.Exts (build)
+import GHC.Generics (Generic)
#endif
-- | A set of values. A set cannot contain duplicate values.
newtype HashSet a = HashSet {
asMap :: HashMap a ()
+#if defined(__GLASGOW_HASKELL__)
+ } deriving (Generic, Typeable)
+#else
} deriving (Typeable)
+#endif
instance (NFData a) => NFData (HashSet a) where
rnf = rnf . asMap
View
1  unordered-containers.cabal
@@ -39,6 +39,7 @@ library
build-depends:
base >= 4 && < 5,
deepseq >= 1.1,
+ ghc-prim >= 0.2,

@2piix, why is this dependency necessary?

@tibbe Owner
tibbe added a note

GHC.Generics is exported by base so it shouldn't be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
hashable >= 1.0.1.1
if impl(ghc < 7.4)
Something went wrong with that request. Please try again.