Skip to content

Commit b233955

Browse files
committed
Read instances
1 parent d7b09ed commit b233955

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Data/HashMap/Base.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import Data.Traversable (Traversable(..))
9393
import Data.Word (Word)
9494
import GHC.Exts ((==#), build, reallyUnsafePtrEquality#)
9595
import Prelude hiding (filter, foldr, lookup, map, null, pred)
96+
import Text.Read hiding (step)
9697

9798
import qualified Data.HashMap.Array as A
9899
import qualified Data.Hashable as H
@@ -173,6 +174,14 @@ type Hash = Word
173174
type Bitmap = Word
174175
type Shift = Int
175176

177+
instance (Eq k, Hashable k, Read k, Read e) => Read (HashMap k e) where
178+
readPrec = parens $ prec 10 $ do
179+
Ident "fromList" <- lexP
180+
xs <- readPrec
181+
return (fromList xs)
182+
183+
readListPrec = readListPrecDefault
184+
176185
instance (Show k, Show v) => Show (HashMap k v) where
177186
showsPrec d m = showParen (d > 10) $
178187
showString "fromList " . shows (toList m)

Data/HashSet.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import qualified Data.Foldable as Foldable
7373
import qualified Data.HashMap.Lazy as H
7474
import qualified Data.List as List
7575
import Data.Typeable (Typeable)
76+
import Text.Read
7677

7778
#if __GLASGOW_HASKELL__ >= 708
7879
import qualified GHC.Exts as Exts
@@ -103,6 +104,14 @@ instance (Hashable a, Eq a) => Monoid (HashSet a) where
103104
mappend = union
104105
{-# INLINE mappend #-}
105106

107+
instance (Eq a, Hashable a, Read a) => Read (HashSet a) where
108+
readPrec = parens $ prec 10 $ do
109+
Ident "fromList" <- lexP
110+
xs <- readPrec
111+
return (fromList xs)
112+
113+
readListPrec = readListPrecDefault
114+
106115
instance (Show a) => Show (HashSet a) where
107116
showsPrec d m = showParen (d > 10) $
108117
showString "fromList " . shows (toList m)

0 commit comments

Comments
 (0)