on master help sign in
Add read instance for benefit of yesod in contractor
commit19de896be1c5bb744f51cae46c97df278128f259 authorVille Tirronen <ville@typeable.io> dateSun 10 Apr 2022, 07:22 (5 years ago) parentc87476a
1 file changed+6
src/Data/Id.hs+6
src/Data/Id.hs+6
@@ -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