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 18, 2021
1 parent 280dea0 commit 5caac2c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
16 changes: 9 additions & 7 deletions random.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ 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,
stm,
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,
stm,
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
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,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.
--
-- @since 1.0.0
Expand Down
1 change: 1 addition & 0 deletions test/doctests.hs
Original file line number Diff line number Diff line change
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 5caac2c

Please sign in to comment.