doc[Type]: haddock

This commit is contained in:
vegowotenks 2025-08-22 11:34:33 +02:00
parent 59ba6e2af5
commit 01d47850f6

View file

@ -31,6 +31,8 @@ import qualified Data.Traversable as Traversable
import qualified Test.QuickCheck.Gen as Gen import qualified Test.QuickCheck.Gen as Gen
import qualified Data.Map as Map import qualified Data.Map as Map
-- | Types a 'Json.Value' can have.
data Type data Type
= Null = Null
| All -- the inverse of any, supertype of all types | All -- the inverse of any, supertype of all types
@ -112,14 +114,18 @@ infer = \case
Value.Object fields -> Object $ infer <$> fields Value.Object fields -> Object $ infer <$> fields
-- | Documents the differences found when checking conformity.
data Mismatch = Mismatch data Mismatch = Mismatch
{ expected :: Type { expected :: Type -- ^ type expected in the layout
, inferred :: Type , inferred :: Type -- ^ type inferred from the input
, value :: Value , value :: Value -- ^ value present in the input
, path :: [Path] , path :: [Path] -- ^ path to get to the value
} }
deriving stock (Show, Eq, Ord) deriving stock (Show, Eq, Ord)
-- | Virtual Field alias
instance HasField "actual" Mismatch Type where instance HasField "actual" Mismatch Type where
getField :: Mismatch -> Type getField :: Mismatch -> Type
getField = (.inferred) getField = (.inferred)
@ -130,6 +136,8 @@ conforms :: Type -> Json.Value -> [Mismatch]
conforms = conforms' [] conforms = conforms' []
-- | Annotate found nonconformities with the value path.
conforms' :: [Path] -> Type -> Value -> [Mismatch] conforms' :: [Path] -> Type -> Value -> [Mismatch]
conforms' path layout value = case (value, layout) of conforms' path layout value = case (value, layout) of
(_, All) -> mempty -- matches all the types (_, All) -> mempty -- matches all the types