Skip to content

Random instance #18

Description

@chris-martin

It would be convenient to have an instance of the Random class for Closed.

It is a pretty straightforward lift from Integer's random.

import Data.Type.Ord
import GHC.TypeLits 

instance (KnownNat a, KnownNat b, a <= b) => Random (Closed a b) where
  randomR (a, b) g =
    let (x, g') = randomR (getClosed a, getClosed b) g
    in  (Closed.unsafeClosed x, g')
  random = randomR (minBound, maxBound)

IMO random is common enough package to put it here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions