Created
November 2, 2016 15:24
-
-
Save heejongahn/ed1c7a7372d1155f3af4ecc1de1b91f9 to your computer and use it in GitHub Desktop.
왜?
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
/Users/nobell/workspace/haskell-study/week7/HW07.hs:68:13: | |
No instance for (MonadRandom Vector) | |
arising from a use of ‘getRandomR’ | |
In a stmt of a 'do' block: victim <- getRandomR (0, i) | |
In the expression: | |
do { victim <- getRandomR (0, i); | |
(unsafeSwapV i victim v) } | |
In an equation for ‘shuffleStep’: | |
shuffleStep v i | |
= do { victim <- getRandomR (0, i); | |
(unsafeSwapV i victim v) } | |
Failed, modules loaded: Cards. |
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
unsafeSwapV :: Int -> Int -> Vector a -> Vector a | |
unsafeSwapV i j v = v // [(i, (v ! j)), (j, (v ! i))] | |
helper :: Vector a -> [Int] -> Rnd (Vector a) | |
helper v idxs = | |
case idxs of | |
[] -> return v | |
(x:xs) -> do | |
let nextV = shuffleStep v x | |
(helper nextV xs) | |
shuffleStep :: Vector a -> Int -> Vector a | |
shuffleStep v i = do | |
victim <- getRandomR (0, i) | |
(unsafeSwapV i victim v) | |
shuffle :: Vector a -> Rnd (Vector a) | |
shuffle v = helper v $ reverse [1.. (length(v) - 1)] |
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
unsafeSwapV :: Int -> Int -> Vector a -> Vector a | |
unsafeSwapV i j v = v // [(i, (v ! j)), (j, (v ! i))] | |
helper :: Vector a -> [Int] -> Rnd (Vector a) | |
helper v idxs = | |
case idxs of | |
[] -> return v | |
(x:xs) -> do | |
nextV <- shuffleStep v x | |
(helper nextV xs) | |
shuffleStep :: Vector a -> Int -> Rnd (Vector a) | |
shuffleStep v i = do | |
victim <- getRandomR (0, i) | |
return (unsafeSwapV i victim v) | |
shuffle :: Vector a -> Rnd (Vector a) | |
shuffle v = helper v $ reverse [1.. (length(v) - 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment