Skip to content

frerich/random-derive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random-derive

Build Status

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.:

{-# LANGUAGE TemplateHaskell #-}

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)

About

A Haskell package providing a utility function for instantiating the System.Random.Random class.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published