mirror of
https://github.com/Lysxia/generic-random.git
synced 2024-09-11 06:35:24 +03:00
Add example with deep BaseCases
This commit is contained in:
parent
f875f7f0f6
commit
ee3ca768f7
@ -1,8 +1,10 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE UndecidableInstances #-}
|
||||
|
||||
import GHC.Generics ( Generic )
|
||||
import GHC.Generics ( Generic, Rep )
|
||||
import Test.QuickCheck
|
||||
import Generic.Random.Generic
|
||||
|
||||
@ -12,4 +14,13 @@ data Tree a = Leaf | Node (Tree a) a (Tree a)
|
||||
instance Arbitrary a => Arbitrary (Tree a) where
|
||||
arbitrary = genericArbitrary' @'Z
|
||||
|
||||
main = sample (arbitrary :: Gen (Tree ()))
|
||||
data Bush a = Tip a | Fork (Bush a) (Bush a)
|
||||
deriving (Show, Generic)
|
||||
|
||||
instance (Arbitrary a, BaseCases' 'Z a) => Arbitrary (Bush a) where
|
||||
arbitrary = genericArbitraryFrequency' @('S 'Z) [1, 2]
|
||||
|
||||
main = do
|
||||
sample (arbitrary :: Gen (Tree ()))
|
||||
putStrLn ""
|
||||
sample (arbitrary :: Gen (Bush ()))
|
||||
|
Loading…
Reference in New Issue
Block a user