on master help sign in
rest of the reads..
commit9378512117839494d7200b0b6115c99af93217f4 authorVille Tirronen <ville@typeable.io> dateMon 11 Apr 2022, 10:55 (5 years ago) parent19de896
1 file changed+10
src/Data/Id.hs+10
src/Data/Id.hs+10
@@ -128,6 +128,11 @@ mkIntId = coerce
128128instance KnownSymbol s => Show (IntId s) where
129129 show (IntId v) = "IntId-" <> symbolVal (Proxy @s) <> "-" <> show v
130130
131+instance KnownSymbol s => Read (IntId s) where
132+ readsPrec _ = readP_to_S $ do
133+ _ <- string ("IntId-" <> symbolVal (Proxy @s) <> "-")
134+ mkIntId <$> readS_to_P reads
135+
131136-- | This is a more \"explicit\" 'coerce' specifically for 'IntId'.
132137-- You are forced to explicitly specify the phantom types you are converting
133138-- via the @TypeApplications@ compiler extension.
@@ -161,6 +166,11 @@ mkName = coerce
161166instance KnownSymbol s => Show (Name s) where
162167 show (Name v) = "Name-" <> symbolVal (Proxy @s) <> "-" <> show v
163168
169+instance KnownSymbol s => Read (Name s) where
170+ readsPrec _ = readP_to_S $ do
171+ _ <- string ("Name-" <> symbolVal (Proxy @s) <> "-")
172+ mkName <$> readS_to_P reads
173+
164174instance Arbitrary (Name s) where
165175 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
166176