@@ -31,6 +31,7 @@ import Data.Csv as Csv hiding(Name)
3131import Flat as F
3232import GHC.TypeLits
3333import Test.QuickCheck
34+import Text.ParserCombinators.ReadP
3435import Web.HttpApiData
3536import Web.PathPieces (PathPiece(..))
3637
@@ -55,6 +56,11 @@ mkId = coerce
5556instance KnownSymbol s => Show (Id s) where
5657 show (Id v) = "Id-" <> symbolVal (Proxy @s) <> "-" <> show v
5758
59+instance KnownSymbol s => Read (Id s) where
60+ readsPrec _ = readP_to_S $ do
61+ _ <- string ("Id-" <> symbolVal (Proxy @s) <> "-")
62+ mkId <$> readS_to_P reads
63+
5864instance Flat (Id s) where
5965 encode = F.encode . UUID.toWords . coerce
6066 decode = coerce . (\(a,b,c,d) -> UUID.fromWords a b c d) <$> F.decode
@@ -122,6 +128,11 @@ mkIntId = coerce
122128instance KnownSymbol s => Show (IntId s) where
123129 show (IntId v) = "IntId-" <> symbolVal (Proxy @s) <> "-" <> show v
124130
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+
125136-- | This is a more \"explicit\" 'coerce' specifically for 'IntId'.
126137-- You are forced to explicitly specify the phantom types you are converting
127138-- via the @TypeApplications@ compiler extension.
@@ -155,6 +166,11 @@ mkName = coerce
155166instance KnownSymbol s => Show (Name s) where
156167 show (Name v) = "Name-" <> symbolVal (Proxy @s) <> "-" <> show v
157168
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+
158174instance Arbitrary (Name s) where
159175 arbitrary = coerce . T.pack . getPrintableString <$> arbitrary
160176