From: malcolm Date: Wed, 28 Sep 2005 13:18:28 +0000 (+0000) Subject: [project @ 2005-09-28 13:18:28 by malcolm] X-Git-Tag: cmm-merge2~21 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=a5cdfc58dcaba282269840df0dfce1890720ebde;p=haskell-directory.git [project @ 2005-09-28 13:18:28 by malcolm] Add an instance of Read to correspond to the existing Show instance. (Implementation based on H'98 Report definition of 'readList'.) --- diff --git a/Data/Set.hs b/Data/Set.hs index eb41f94..99ba4a1 100644 --- a/Data/Set.hs +++ b/Data/Set.hs @@ -34,7 +34,7 @@ module Data.Set ( -- * Set type - Set -- instance Eq,Show + Set -- instance Eq,Ord,Show,Read,Data,Typeable -- * Operators , (\\) @@ -522,9 +522,21 @@ showSet (x:xs) where showTail [] = showChar '}' showTail (x:xs) = showChar ',' . shows x . showTail xs - {-------------------------------------------------------------------- + Read +--------------------------------------------------------------------} +instance (Read a, Ord a) => Read (Set a) where + readsPrec i r = [ (fromList xs, t) | ("{",s) <- lex r, (xs,t) <- readl s ] + where readl s = [([],t) | ("}",t) <- lex s] ++ + [(x:xs,u) | (x,t) <- readsPrec i s + , (xs,u) <- readl' t] + readl' s = [([],t) | ("}",t) <- lex s] ++ + [(x:xs,v) | (",",t) <- lex s + , (x,u) <- readsPrec i t + , (xs,v) <- readl' u] + +{-------------------------------------------------------------------- Typeable/Data --------------------------------------------------------------------}