diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml new file mode 100644 index 00000000..9bb22c7e --- /dev/null +++ b/.github/workflows/doctest.yml @@ -0,0 +1,18 @@ +name: doctest + +on: + pull_request: + branches: + - master + +jobs: + doctest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - run: cabal update + + # 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' diff --git a/.gitignore b/.gitignore index 45cb6726..ecd83243 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -stack.yaml.lock -.stack-work/ -cabal.project.local +/dist-newstyle/ +/stack.yaml.lock +/.stack-work/ +/cabal.project.local diff --git a/random.cabal b/random.cabal index 262f3ace..0d635a37 100644 --- a/random.cabal +++ b/random.cabal @@ -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 diff --git a/src/System/Random.hs b/src/System/Random.hs index 356c69fe..35d4c799 100644 --- a/src/System/Random.hs +++ b/src/System/Random.hs @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -842,3 +842,4 @@ randomIO = getStdRandom random -- -- >>> import Control.Monad (replicateM) -- >>> import Data.List (unfoldr) +-- >>> setStdGen (mkStdGen 0) diff --git a/src/System/Random/Internal.hs b/src/System/Random/Internal.hs index 9d0c33a5..a193f438 100644 --- a/src/System/Random/Internal.hs +++ b/src/System/Random/Internal.hs @@ -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) @@ -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) @@ -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) diff --git a/src/System/Random/Stateful.hs b/src/System/Random/Stateful.hs index c89b02b3..56d614c0 100644 --- a/src/System/Random/Stateful.hs +++ b/src/System/Random/Stateful.hs @@ -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 diff --git a/stack-old.yaml b/stack-old.yaml index 5c749977..8b10ec6e 100644 --- a/stack-old.yaml +++ b/stack-old.yaml @@ -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 diff --git a/test/doctests.hs b/test/doctests.hs deleted file mode 100644 index 001b3376..00000000 --- a/test/doctests.hs +++ /dev/null @@ -1,18 +0,0 @@ -{-# LANGUAGE CPP #-} -module Main where - -#if __GLASGOW_HASKELL__ >= 802 && __GLASGOW_HASKELL__ < 810 - -import Test.DocTest (doctest) - -main :: IO () -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" - -#endif