diff options
author | daniel <daniel@wagner-home.com> | 2007-06-02 08:43:18 +0200 |
---|---|---|
committer | daniel <daniel@wagner-home.com> | 2007-06-02 08:43:18 +0200 |
commit | 84ac66c9f2e4fb0aacc569e33427719e5efb9661 (patch) | |
tree | 2363a0604a9ae0a4cbf8b596a6d0687edb0fb7e5 | |
parent | a901a51afaa6455a2da04aae1db331bb085f9521 (diff) | |
download | XMonadContrib-84ac66c9f2e4fb0aacc569e33427719e5efb9661.tar.gz XMonadContrib-84ac66c9f2e4fb0aacc569e33427719e5efb9661.tar.xz XMonadContrib-84ac66c9f2e4fb0aacc569e33427719e5efb9661.zip |
XMonadContrib.ReadMap: a Read instance of Map for GHC 6.4 users
darcs-hash:20070602064318-c98ca-694cb6f4b95c855bdfdc7dc9d311dd41f3954732.gz
Diffstat (limited to '')
-rw-r--r-- | ReadMap.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ReadMap.hs b/ReadMap.hs new file mode 100644 index 0000000..ab64815 --- /dev/null +++ b/ReadMap.hs @@ -0,0 +1,33 @@ +module XMonadContrib.ReadMap () where + +{- An instance of Read for Data.Map.Map's; useful for people that are still + - compiling under 6.4. To use it, add the following line to StackSet.hs: + - import XMonadContrib.ReadMap + -} + +import Data.Map (Map, fromList) +import GHC.Read + +instance (Ord k, Read k, Read e) => Read (Map k e) where + readsPrec _ = \s1 -> do + ("{", s2) <- lex s1 + (xs, s3) <- readPairs s2 + ("}", s4) <- lex s3 + return (fromList xs, s4) + +-- parses a pair of things with the syntax a:=b +-- stolen from the GHC 6.6 sources +readPair :: (Read a, Read b) => ReadS (a,b) +readPair s = do (a, ct1) <- reads s + (":=", ct2) <- lex ct1 + (b, ct3) <- reads ct2 + return ((a,b), ct3) + +readPairs :: (Read a, Read b) => ReadS [(a,b)] +readPairs s1 = case readPair s1 of + [(p, s2)] -> case s2 of + (',':s3) -> do + (ps, s4) <- readPairs s3 + return (p:ps, s4) + _ -> [([p], s2)] + _ -> [([],s1)] |