Created
June 5, 2015 20:05
-
-
Save rpglover64/740040c28b725cd93337 to your computer and use it in GitHub Desktop.
Implementation of shuffle for smallcheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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