Skip to content

Commit

Permalink
Add genValue function
Browse files Browse the repository at this point in the history
  • Loading branch information
paolino committed Aug 23, 2023
1 parent 55361f5 commit b4dc24a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/fine-types/src/Language/FineTypes/Value/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Language.FineTypes.Value.Gen
( genTypValue
, genTypValue'
, genValue
)
where

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit b4dc24a

Please sign in to comment.