Skip to content

Commit

Permalink
Add a few doctest examples for randomR. Disable deps for unrunndabl…
Browse files Browse the repository at this point in the history
…e doctests
  • Loading branch information
lehins committed Sep 11, 2021
1 parent 01ee33f commit 5fe6230
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions random.cabal
Expand Up @@ -137,12 +137,14 @@ test-suite doctests
default-language: Haskell2010
build-depends:
base,
doctest >=0.15 && <0.19,
mwc-random >=0.13 && <0.16,
primitive >=0.6 && <0.8,
random,
unliftio >=0.2 && <0.3,
vector >= 0.10 && <0.14
doctest >=0.15 && <0.19
if impl(ghc >= 8.2) && impl(ghc < 8.10)
build-depends:
mwc-random >=0.13 && <0.16,
primitive >=0.6 && <0.8,
random,
unliftio >=0.2 && <0.3,
vector >= 0.10 && <0.14

test-suite spec
type: exitcode-stdio-1.0
Expand Down
13 changes: 12 additions & 1 deletion src/System/Random.hs
Expand Up @@ -219,12 +219,23 @@ class Random a where
-- closed interval /[lo,hi]/, together with a new generator. It is unspecified
-- what happens if /lo>hi/, but usually the values will simply get swapped.
--
-- >>> let gen = mkStdGen 2021
-- >>> fst $ randomR ('a', 'z') gen
-- 't'
-- >>> fst $ randomR ('z', 'a') gen
-- 't'
--
-- For continuous types there is no requirement that the values /lo/ and /hi/ are ever
-- produced, but they may be, depending on the implementation and the interval.
--
-- There is no requirement to follow the @Ord@ instance and the concept of range can be
-- defined on per type basis. For example product types will treat their values
-- independently. In case when a lawful range is desired `uniformR` should be used
-- independently:
--
-- >>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021
-- ('t',6.240232662366563)
--
-- In case when a lawful range is desired `uniformR` should be used
-- instead.
{-# INLINE randomR #-}
randomR :: RandomGen g => (a, a) -> g -> (a, g)
Expand Down
1 change: 1 addition & 0 deletions test/doctests.hs
Expand Up @@ -10,6 +10,7 @@ main = doctest ["src"]

#else

-- Also disabled in cabal file.
-- TODO: fix doctest support
main :: IO ()
main = putStrLn "\nDoctests are not supported for older ghc version\n"
Expand Down

0 comments on commit 5fe6230

Please sign in to comment.