Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jul 29, 2024
1 parent 623cf51 commit 67badc6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 50 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/doctest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: doctest

on:
pull_request:
branches:
- master

jobs:
doctest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# NOTE: We can't use `cabal doctest` here, as `cabal doctest` uses
# `--build-depends=QuickCheck`, which results in a dependency cycle.
- run: cabal install doctest --ignore-project --overwrite-policy=always && cabal build && cabal repl --build-depends=unliftio --with-compiler=doctest --repl-options='-w -Wdefault'
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
stack.yaml.lock
.stack-work/
cabal.project.local
/dist-newstyle/
/stack.yaml.lock
/.stack-work/
/cabal.project.local
16 changes: 0 additions & 16 deletions random.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@ test-suite legacy-test
containers >=0.5 && <0.7,
random

test-suite doctests
type: exitcode-stdio-1.0
main-is: doctests.hs
hs-source-dirs: test
default-language: Haskell2010
build-depends:
base,
doctest >=0.15 && <0.23
if impl(ghc >= 8.2) && impl(ghc < 8.10)
build-depends:
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
main-is: Spec.hs
Expand Down
15 changes: 8 additions & 7 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class Random a where
-- independently:
--
-- >>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021
-- ('t',6.240232662366563)
-- ('t',6.240232662366564)
--
-- In case when a lawful range is desired `uniformR` should be used
-- instead.
Expand Down Expand Up @@ -642,7 +642,7 @@ newStdGen = liftIO $ atomicModifyIORef' theStdGen splitGen
--
-- >>> rollDice = getStdRandom (randomR (1, 6))
-- >>> replicateM 10 (rollDice :: IO Int)
-- [5,6,6,1,1,6,4,2,4,1]
-- [1,1,1,4,5,6,1,2,2,5]
--
-- This is an outdated function and it is recommended to switch to its
-- equivalent 'System.Random.Stateful.applyAtomicGen' instead, possibly with the
Expand All @@ -652,7 +652,7 @@ newStdGen = liftIO $ atomicModifyIORef' theStdGen splitGen
-- >>> import System.Random.Stateful
-- >>> rollDice = applyAtomicGen (uniformR (1, 6)) globalStdGen
-- >>> replicateM 10 (rollDice :: IO Int)
-- [4,6,1,1,4,4,3,2,1,2]
-- [2,1,1,5,4,3,6,6,3,2]
--
-- @since 1.0.0
getStdRandom :: MonadIO m => (StdGen -> (a, StdGen)) -> m a
Expand All @@ -664,7 +664,7 @@ getStdRandom f = liftIO $ atomicModifyIORef' theStdGen (swap . f)
-- pseudo-random number generator 'System.Random.Stateful.globalStdGen'
--
-- >>> randomRIO (2020, 2100) :: IO Int
-- 2040
-- 2028
--
-- Similar to 'randomIO', this function is equivalent to @'getStdRandom'
-- 'randomR'@ and is included in this interface for historical reasons and
Expand All @@ -675,7 +675,7 @@ getStdRandom f = liftIO $ atomicModifyIORef' theStdGen (swap . f)
--
-- >>> import System.Random.Stateful
-- >>> uniformRM (2020, 2100) globalStdGen :: IO Int
-- 2079
-- 2044
--
-- @since 1.0.0
randomRIO :: (Random a, MonadIO m) => (a, a) -> m a
Expand All @@ -686,7 +686,7 @@ randomRIO range = getStdRandom (randomR range)
--
-- >>> import Data.Int
-- >>> randomIO :: IO Int32
-- -1580093805
-- 114794456
--
-- This function is equivalent to @'getStdRandom' 'random'@ and is included in
-- this interface for historical reasons and backwards compatibility. It is
Expand All @@ -696,7 +696,7 @@ randomRIO range = getStdRandom (randomR range)
--
-- >>> import System.Random.Stateful
-- >>> uniformM globalStdGen :: IO Int32
-- -1649127057
-- -1768545016
--
-- @since 1.0.0
randomIO :: (Random a, MonadIO m) => m a
Expand Down Expand Up @@ -842,3 +842,4 @@ randomIO = getStdRandom random
--
-- >>> import Control.Monad (replicateM)
-- >>> import Data.List (unfoldr)
-- >>> setStdGen (mkStdGen 0)
6 changes: 3 additions & 3 deletions src/System/Random/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ class Uniform a where
--
-- There is a default implementation via 'Generic':
--
-- >>> :set -XDeriveGeneric -XDeriveAnyClass
-- >>> :seti -XDeriveGeneric -XDeriveAnyClass
-- >>> import GHC.Generics (Generic)
-- >>> import System.Random.Stateful
-- >>> data MyBool = MyTrue | MyFalse deriving (Show, Generic, Finite, Uniform)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ finiteUniformM = fmap toGFinite . case gcardinality (proxy# :: Proxy# f) of
-- If your data has several fields of sub-'Word' cardinality,
-- this instance may be more efficient than one, derived via 'Generic' and 'GUniform'.
--
-- >>> :set -XDeriveGeneric -XDeriveAnyClass
-- >>> :seti -XDeriveGeneric -XDeriveAnyClass
-- >>> import GHC.Generics (Generic)
-- >>> import System.Random.Stateful
-- >>> data Triple = Triple Word8 Word8 Word8 deriving (Show, Generic, Finite)
Expand Down Expand Up @@ -1055,7 +1055,7 @@ class UniformRange a where
--
-- There is a default implementation via 'Generic':
--
-- >>> :set -XDeriveGeneric -XDeriveAnyClass
-- >>> :seti -XDeriveGeneric -XDeriveAnyClass
-- >>> import GHC.Generics (Generic)
-- >>> import Data.Word (Word8)
-- >>> import Control.Monad (replicateM)
Expand Down
2 changes: 1 addition & 1 deletion src/System/Random/Stateful.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ withMutableGen_ fg action = thawGen fg >>= action
--
-- >>> :set -XTypeApplications
-- >>> randomM @Double g
-- 0.6268211351114487
-- 0.6268211351114488
--
-- @since 1.2.0
randomM :: forall a g m. (Random a, RandomGen g, FrozenGen g m) => MutableGen g m -> m a
Expand Down
2 changes: 0 additions & 2 deletions stack-old.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ packages:
- .
extra-deps:
- splitmix-0.1@sha256:d50c4d0801a35be7875a040470c09863342514930c82a7d25780a6c2efc4fda9,5249
- doctest-0.16.2@sha256:2f96e9bbe9aee11b47453c82c24b3dc76cdbb8a2a7c984dfd60b4906d08adf68,6942
- cabal-doctest-1.0.8@sha256:34dff6369d417df2699af4e15f06bc181d495eca9c51efde173deae2053c197c,1491
- rdtsc-1.3.0.1@sha256:0a6e8dc715ba82ad72c7e2b1c2f468999559bec059d50540719a80b00dcc4e66,1557
- smallcheck-1.2.0@sha256:8b431572e6a0503223e0e52014d41084c1b01f2aeea3bd499f6f529b3f6dfa89,1482
- tasty-1.3.1@sha256:01e35c97f7ee5ccbc28f21debea02a38cd010d53b4c3087f5677c5d06617a507,2520
Expand Down
18 changes: 0 additions & 18 deletions test/doctests.hs

This file was deleted.

0 comments on commit 67badc6

Please sign in to comment.