From: ross Date: Fri, 21 Oct 2005 10:39:56 +0000 (+0000) Subject: [project @ 2005-10-21 10:39:56 by ross] X-Git-Tag: cmm-merge2~1 X-Git-Url: http://git.megacz.com/?p=haskell-directory.git;a=commitdiff_plain;h=a5d8b45865712ab237eee066f37c667f3574f7ac [project @ 2005-10-21 10:39:56 by ross] conformant Show and Read instances --- diff --git a/Data/IntSet.hs b/Data/IntSet.hs index 4dc1bf7..c41ed17 100644 --- a/Data/IntSet.hs +++ b/Data/IntSet.hs @@ -104,6 +104,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 @@ -582,7 +583,8 @@ instance Ord IntSet where Show --------------------------------------------------------------------} instance Show IntSet where - showsPrec d s = showSet (toList s) + showsPrec p xs = showParen (p > 10) $ + showString "fromList " . shows (toList xs) showSet :: [Int] -> ShowS showSet [] @@ -594,6 +596,22 @@ showSet (x:xs) showTail (x:xs) = showChar ',' . shows x . showTail xs {-------------------------------------------------------------------- + Read +--------------------------------------------------------------------} +instance Read IntSet 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 --------------------------------------------------------------------} diff --git a/Data/Set.hs b/Data/Set.hs index 33641de..fd09eb0 100644 --- a/Data/Set.hs +++ b/Data/Set.hs @@ -123,6 +123,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 @@ -512,7 +513,8 @@ instance Ord a => Ord (Set a) where Show --------------------------------------------------------------------} instance Show a => Show (Set a) where - showsPrec d s = showSet (toAscList s) + showsPrec p xs = showParen (p > 10) $ + showString "fromList " . shows (toList xs) showSet :: (Show a) => [a] -> ShowS showSet [] @@ -527,17 +529,18 @@ showSet (x:xs) Read --------------------------------------------------------------------} instance (Read a, Ord a) => Read (Set a) where - readsPrec _ = readParen False $ \ r -> - [(fromList xs,t) | ("{",s) <- lex r, - (xs,t) <- readl s] - where readl s = [([],t) | ("}",t) <- lex s] ++ - [(x:xs,u) | (x,t) <- reads s - , (xs,u) <- readl' t] - readl' s = [([],t) | ("}",t) <- lex s] ++ - [(x:xs,v) | (",",t) <- lex s - , (x,u) <- reads t - , (xs,v) <- readl' u] - +#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/Data --------------------------------------------------------------------}