1
1
{-# LANGUAGE BangPatterns, CPP, ForeignFunctionInterface, MagicHash,
2
- ScopedTypeVariables, UnliftedFFITypes #-}
2
+ ScopedTypeVariables, UnliftedFFITypes, DeriveDataTypeable #-}
3
3
#ifdef GENERICS
4
4
{-# LANGUAGE DefaultSignatures, FlexibleContexts, GADTs,
5
5
MultiParamTypeClasses, EmptyDataDecls #-}
@@ -50,6 +50,8 @@ module Data.Hashable.Class
50
50
, Hashed
51
51
, hashed
52
52
, unhashed
53
+ , mapHashed
54
+ , traverseHashed
53
55
) where
54
56
55
57
import Control.Applicative (Const (.. ))
@@ -66,7 +68,7 @@ import qualified Data.Text as T
66
68
import qualified Data.Text.Array as TA
67
69
import qualified Data.Text.Internal as T
68
70
import qualified Data.Text.Lazy as TL
69
- import Data.Typeable
71
+ import Data.Typeable ( Typeable , TypeRep )
70
72
import Data.Version (Version (.. ))
71
73
import Data.Word (Word8 , Word16 , Word32 , Word64 )
72
74
import Foreign.C (CString )
@@ -80,7 +82,10 @@ import System.IO.Unsafe (unsafePerformIO)
80
82
import System.Mem.StableName
81
83
import Data.Unique (Unique , hashUnique )
82
84
83
- #if !(MIN_VERSION_base(4,7,0))
85
+ -- As we use qualified F.Foldable, we don't get warnings with newer base
86
+ import qualified Data.Foldable as F
87
+
88
+ #if MIN_VERSION_base(4,7,0)
84
89
import Data.Proxy (Proxy )
85
90
#endif
86
91
@@ -97,10 +102,13 @@ import GHC.Generics
97
102
#endif
98
103
99
104
#if __GLASGOW_HASKELL__ >= 710
105
+ import Data.Typeable (typeRepFingerprint )
100
106
import GHC.Fingerprint.Type (Fingerprint (.. ))
101
107
#elif __GLASGOW_HASKELL__ >= 702
102
- import Data.Typeable.Internal (TypeRep (.. ))
108
+ import Data.Typeable.Internal (TypeRep (.. ))
103
109
import GHC.Fingerprint.Type (Fingerprint (.. ))
110
+ #elif __GLASGOW_HASKELL__ >= 606
111
+ import Data.Typeable (typeRepKey )
104
112
#endif
105
113
106
114
#if __GLASGOW_HASKELL__ >= 703
@@ -747,12 +755,14 @@ instance Hashable a => Hashable1 (Const a) where
747
755
instance Hashable2 Const where
748
756
liftHashWithSalt2 f _ salt (Const x) = f salt x
749
757
758
+ #if MIN_VERSION_base(4,7,0)
750
759
instance Hashable (Proxy a ) where
751
760
hash _ = 0
752
761
hashWithSalt s _ = s
753
762
754
763
instance Hashable1 Proxy where
755
764
liftHashWithSalt _ s _ = s
765
+ #endif
756
766
757
767
-- instances formerly provided by 'semigroups' package
758
768
#if MIN_VERSION_base(4,9,0)
@@ -842,9 +852,17 @@ instance Hashable1 Hashed where
842
852
instance (IsString a , Hashable a ) => IsString (Hashed a ) where
843
853
fromString s = let r = fromString s in Hashed r (hash r)
844
854
845
- instance Foldable Hashed where
855
+ instance F. Foldable Hashed where
846
856
foldr f acc (Hashed a _) = f a acc
847
857
858
+ -- | 'Hashed' cannot be 'Functor'
859
+ mapHashed :: Hashable b => (a -> b ) -> Hashed a -> Hashed b
860
+ mapHashed f (Hashed a _) = hashed (f a)
861
+
862
+ -- | 'Hashed' cannot be 'Traversable'
863
+ traverseHashed :: (Hashable b , Functor f ) => (a -> f b ) -> Hashed a -> f (Hashed b )
864
+ traverseHashed f (Hashed a _) = fmap hashed (f a)
865
+
848
866
-- instances for @Data.Functor.Classes@ higher rank typeclasses
849
867
-- in base-4.9 and onward.
850
868
#if MIN_VERSION_base(4,9,0)
0 commit comments