mirror of
https://github.com/Lysxia/generic-random.git
synced 2024-09-11 06:35:24 +03:00
Add example
This commit is contained in:
parent
bc52c26e50
commit
225890081f
24
examples/BinaryTree.hs
Normal file
24
examples/BinaryTree.hs
Normal file
@ -0,0 +1,24 @@
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
module BinaryTree where
|
||||
|
||||
import Data.Data
|
||||
import Data.Random.Generics
|
||||
|
||||
data T = N T T | L
|
||||
deriving (Eq, Ord, Show, Data)
|
||||
|
||||
-- size
|
||||
s :: T -> Integer
|
||||
s (N l r) = 1 + s l + s r
|
||||
s L = 1
|
||||
|
||||
mBoltz :: IO T
|
||||
mBoltz = makeGenerator randomPrimRandom undefined 0 10
|
||||
|
||||
-- Pointing makes the generator more precise.
|
||||
mPoint :: IO T
|
||||
mPoint = makeGenerator randomPrimRandom undefined 1 10
|
||||
|
||||
-- Rejection is more elementary and works fine too.
|
||||
mReject :: IO T
|
||||
mReject = randomGenerator 10
|
Loading…
Reference in New Issue
Block a user