From b081a2fa09f95f72036fdedbae86799ab0d78840 Mon Sep 17 00:00:00 2001 From: VegOwOtenks Date: Fri, 22 Aug 2025 11:17:53 +0200 Subject: [PATCH] doc[type] --- src/Language/Json/Type.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Language/Json/Type.hs b/src/Language/Json/Type.hs index 2df689a..023c325 100644 --- a/src/Language/Json/Type.hs +++ b/src/Language/Json/Type.hs @@ -85,6 +85,8 @@ isObject = \case Object _ -> True _ -> False +-- | Find the type of a value. + infer :: Json.Value -> Type infer = \case Value.Null -> Null @@ -107,6 +109,8 @@ instance HasField "actual" Mismatch Type where getField :: Mismatch -> Type getField = (.inferred) +-- | Compute all the differences to the expected type. Empty List means that the value is conforming. + conforms :: Type -> Json.Value -> [Mismatch] conforms = conforms' [] @@ -135,6 +139,8 @@ conforms' path layout value = case (value, layout) of else Foldable.concatMap id mismatches _ -> pure $ Mismatch {expected=layout, inferred=infer value, value=value, path=path} +-- | Choose any arbitrary value conforming to the type. + sample :: Type -> Gen Value sample = \case All -> arbitrary