diff --git a/lib/fine-types/src/Language/FineTypes/Value/Gen.hs b/lib/fine-types/src/Language/FineTypes/Value/Gen.hs index a0ebb67..7f1cbd0 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)