mirror of
https://github.com/Lysxia/generic-random.git
synced 2024-08-16 01:50:38 +03:00
30 lines
780 B
Haskell
30 lines
780 B
Haskell
{-# LANGUAGE DataKinds #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
{-# LANGUAGE UndecidableInstances #-}
|
|
|
|
import GHC.Generics (Generic)
|
|
import Test.QuickCheck
|
|
import Generic.Random
|
|
|
|
data Tree a = Leaf | Node (Tree a) a (Tree a)
|
|
deriving (Show, Generic)
|
|
|
|
instance Arbitrary a => Arbitrary (Tree a) where
|
|
arbitrary = genericArbitrary' uniform
|
|
|
|
data Bush a = Tip a | Fork (Bush a) (Bush a)
|
|
deriving (Show, Generic)
|
|
|
|
instance (Arbitrary a, BaseCase (Bush a)) => Arbitrary (Bush a) where
|
|
arbitrary = genericArbitrary' (1 % (2 % ()))
|
|
|
|
main :: IO ()
|
|
main = do
|
|
sample (arbitrary :: Gen (Tree ()))
|
|
putStrLn ""
|
|
sample (arbitrary :: Gen (Bush ()))
|