Copyright | (c) 2015 Frerich Raabe |
---|---|

License | BSD3 |

Maintainer | frerich.raabe@gmail.com |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

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)

- deriveRandom :: Name -> Q [Dec]

# Documentation

deriveRandom :: Name -> Q [Dec] Source

The `deriveRandom`

function derives a Random instance for the given type.