sampling

Basic sampling functionality for Haskell.
Log | Files | Refs | README | LICENSE

commit 201fa11eef1077c948ddff0d5ff99e4a68e12ef9
parent 0df6c60f3f31b7973b73d75b20a94e2bfb403f1e
Author: Jared Tobin <jared@jtobin.ca>
Date:   Thu,  3 Mar 2016 21:34:00 +1300

Return lists rather than vectors.

Diffstat:
Mlib/Numeric/Sampling.hs | 8++++----
Msampling.cabal | 2+-
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/Numeric/Sampling.hs b/lib/Numeric/Sampling.hs @@ -29,7 +29,7 @@ import Data.Foldable (Foldable) #endif import Data.Function (on) import Data.List (sortBy) -import Data.Vector (Vector) +import qualified Data.Vector as V (toList) import Numeric.Sampling.Internal import System.Random.MWC @@ -39,14 +39,14 @@ import System.Random.MWC -- being sampled from. sample :: (PrimMonad m, Foldable f) - => Int -> f a -> Gen (PrimState m) -> m (Maybe (Vector a)) + => Int -> f a -> Gen (PrimState m) -> m (Maybe [a]) sample n xs gen | n < 0 = return Nothing - | otherwise = F.foldM (randomN n gen) xs + | otherwise = fmap (fmap V.toList) (F.foldM (randomN n gen) xs) {-# INLINABLE sample #-} -- | (/O(n)/) 'sample' specialized to IO. -sampleIO :: Foldable f => Int -> f a -> IO (Maybe (Vector a)) +sampleIO :: Foldable f => Int -> f a -> IO (Maybe [a]) sampleIO n xs = do gen <- createSystemRandom sample n xs gen diff --git a/sampling.cabal b/sampling.cabal @@ -1,5 +1,5 @@ name: sampling -version: 0.1.1 +version: 0.2.0 synopsis: Sample values from collections. homepage: https://github.com/jtobin/sampling license: MIT