random-derive-0.1.0.0: A Template Haskell helper for deriving Random instances

Copyright(c) 2015 Frerich Raabe
LicenseBSD3
Maintainerfrerich.raabe@gmail.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

System.Random.TH

Description

This module exposes a deriveRandom function which automatically creates Random instances for data types instantiating both Enum as well as Bounded.

This is useful for getting random values (or sequences of random values) of custom types, e.g.:


import System.Random (mkStdGen, randoms)
import System.Random.TH

data Color = Red | Green | Blue deriving (Enum, Bounded)

$(deriveRandom ''Color)

-- Yields an infinite sequence of random colors given some initial seed.
randomColors :: Int -> [Color]
randomColors seed = randoms (mkStdGen seed)

Synopsis

Documentation

deriveRandom :: Name -> Q [Dec] Source

The deriveRandom function derives a Random instance for the given type.