[project @ 2005-10-21 10:24:58 by ross]
authorross <unknown>
Fri, 21 Oct 2005 10:24:58 +0000 (10:24 +0000)
committerross <unknown>
Fri, 21 Oct 2005 10:24:58 +0000 (10:24 +0000)
export parens, which is useful for writing Read instances.

Text/Read.hs

index 16a4d15..bcb2d09 100644 (file)
@@ -35,6 +35,7 @@ module Text.Read (
    module Text.ParserCombinators.ReadPrec,
    L.Lexeme(..),       
    lexP,               -- :: ReadPrec Lexeme
+   parens,             -- :: ReadPrec a -> ReadPrec a
 #endif
 #ifdef __GLASGOW_HASKELL__
    readListDefault,    -- :: Read a => ReadS [a]
@@ -56,4 +57,14 @@ import qualified Text.Read.Lex as L
 
 lexP :: ReadPrec L.Lexeme
 lexP = lift L.lex
+
+parens :: ReadPrec a -> ReadPrec a
+parens p = optional
+ where
+  optional  = p +++ mandatory
+  mandatory = do
+    L.Punc "(" <- lexP
+    x          <- reset optional
+    L.Punc ")" <- lexP
+    return x
 #endif