X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=Data%2FIntMap.hs;h=318fe59c621025f4e59bd0fa11d867ec09c28904;hb=793cc56fbad9da3087e0b26800aec46687ce82dd;hp=ff9d30b7c5e92ca2233471fdd68eed949689d35e;hpb=a5d8b45865712ab237eee066f37c667f3574f7ac;p=haskell-directory.git diff --git a/Data/IntMap.hs b/Data/IntMap.hs index ff9d30b..318fe59 100644 --- a/Data/IntMap.hs +++ b/Data/IntMap.hs @@ -147,6 +147,7 @@ import qualified List -} #if __GLASGOW_HASKELL__ +import Text.Read (Lexeme(Ident), lexP, parens, prec, readPrec) import Data.Generics.Basics import Data.Generics.Instances #endif @@ -978,8 +979,8 @@ instance Functor IntMap where --------------------------------------------------------------------} instance Show a => Show (IntMap a) where - showsPrec d t = showMap (toList t) - + showsPrec d m = showParen (d > 10) $ + showString "fromList " . shows (toList m) showMap :: (Show a) => [(Key,a)] -> ShowS showMap [] @@ -991,7 +992,23 @@ showMap (x:xs) showTail (x:xs) = showChar ',' . showElem x . showTail xs showElem (k,x) = shows k . showString ":=" . shows x - + +{-------------------------------------------------------------------- + Read +--------------------------------------------------------------------} +instance (Read e) => Read (IntMap e) where +#ifdef __GLASGOW_HASKELL__ + readPrec = parens $ prec 10 $ do + Ident "fromList" <- lexP + xs <- readPrec + return (fromList xs) +#else + readsPrec p = readParen (p > 10) $ \ r -> do + ("fromList",s) <- lex + (xs,t) <- reads + return (fromList xs,t) +#endif + {-------------------------------------------------------------------- Typeable --------------------------------------------------------------------}