From b4dc24a9934d0def937711ba738fc34f0aaec69c Mon Sep 17 00:00:00 2001 From: paolino Date: Wed, 23 Aug 2023 12:08:56 +0200 Subject: [PATCH] Add genValue function --- lib/fine-types/src/Language/FineTypes/Value/Gen.hs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/fine-types/src/Language/FineTypes/Value/Gen.hs b/lib/fine-types/src/Language/FineTypes/Value/Gen.hs index a0ebb673..7f1cbd07 100644 --- a/lib/fine-types/src/Language/FineTypes/Value/Gen.hs +++ b/lib/fine-types/src/Language/FineTypes/Value/Gen.hs @@ -4,6 +4,7 @@ module Language.FineTypes.Value.Gen ( genTypValue , genTypValue' + , genValue ) where @@ -30,6 +31,7 @@ import Test.QuickCheck , listOf , oneof ) +import Language.FineTypes.Typ.Gen (Concrete (..), DepthGen (..), genTyp) import qualified Data.ByteString as B import qualified Data.Map as Map @@ -54,7 +56,7 @@ listOfT :: (Monad (t Gen), MonadTrans t) => t Gen a -> t Gen [a] listOfT f = do l <- lift getSize replicateM l f - + -- | Generate a random 'Value' of the given 'Typ' or report the first 'Typ' that -- cannot be generated down the tree. genTypValue :: Typ -> Gen (Either Typ Value) @@ -119,3 +121,9 @@ genTypValue' typ = do case r of Left typ' -> error $ "typeValueGenE: " <> show typ' Right v -> pure v + +genValue :: DepthGen -> Gen (Typ, Either Typ Value) +genValue dg = do + typ <- genTyp Concrete dg + r <- genTypValue typ + pure (typ, r)