ref: 977b959064ac1d5d3ceba5ad7a32e29bb46bfc0c
parent: 25faeffbcee9b8006aa5e8083ea81eadcca8367e
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Mon Feb 5 15:28:38 EST 2024
More Read
--- a/lib/Text/Read.hs
+++ b/lib/Text/Read.hs
@@ -82,3 +82,14 @@
readsPrec p = readParen (p > 10) $ \ r ->
[ (Left a, t) | ("Left", s) <- lex r, (a, t) <- readsPrec 11 s ] ++ [ (Right b, t) | ("Right", s) <- lex r, (b, t) <- readsPrec 11 s ]+
+instance Read () where
+ readsPrec p = readParen False $
+ \ r -> [((),t) | ("(",s) <- lex r,+ (")",t) <- lex s ]+
+instance forall a b . (Read a, Read b) => Read (a,b) where
+ readsPrec p = readParen True $
+ \ r -> [((a, b), u) | (a, s) <- reads r,
+ (",", t) <- lex s,+ (b, u) <- reads t ]
--- a/tests/Read.hs
+++ b/tests/Read.hs
@@ -45,3 +45,5 @@
print (readMaybe "Just Just 123" :: Maybe (Maybe (Maybe Int)))
print (read "Left True" :: Either Bool Int)
print (read "Right 123" :: Either Bool Int)
+ print (read "()" :: ())
+ print (read "(True,123)" :: (Bool, Int))
--- a/tests/Read.ref
+++ b/tests/Read.ref
@@ -35,3 +35,5 @@
Nothing
Left True
Right 123
+()
+(True,123)
--
⑨