Skip to content

Instantly share code, notes, and snippets.

@rpglover64
Created June 5, 2015 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpglover64/740040c28b725cd93337 to your computer and use it in GitHub Desktop.
Save rpglover64/740040c28b725cd93337 to your computer and use it in GitHub Desktop.
Implementation of shuffle for smallcheck
import Test.SmallCheck
import Test.SmallCheck.Series
import Data.Bifunctor
import Control.Monad
-- Based on the implementation in quickcheck: http://hackage.haskell.org/package/QuickCheck-2.8.1/docs/src/Test-QuickCheck-Gen.html#shuffle
shuffle [] = return []
shuffle xs = do
(y, ys) <- uncurry mplus $ bimap msum msum $ bimap (map return) (map $ decDepth . return) $ splitAt 1 $ selectOne xs
(y:) <$> decDepthChecked (return ys) (shuffle ys)
where selectOne [] = []
selectOne (y:ys) = (y,ys) : map (second (y:)) (selectOne ys)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment