Commit a5d8b458 authored by ross's avatar ross

[project @ 2005-10-21 10:39:56 by ross]

conformant Show and Read instances
parent d7316cd3
......@@ -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 []
......@@ -593,6 +595,22 @@ showSet (x:xs)
showTail [] = showChar '}'
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
--------------------------------------------------------------------}
......
......@@ -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
--------------------------------------------------------------------}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment