fork(3) download
  1. import System.Random
  2.  
  3. shuffle :: Int -> [Int] -> IO [Int]
  4. shuffle 0 xs = return xs
  5. shuffle i xs = do
  6. n <- getStdRandom $ randomR (0, (length xs) - 1) :: IO Int
  7. let part1 = take n xs
  8. part2 = drop (n + 1) xs
  9. flipped = [xs !! n] ++ part1 ++ part2
  10. return (shuffle (i - 1) flipped)
  11.  
  12. main = do
  13. shuffle 10 [1..9] >>= print
Compilation error #stdin compilation error #stdout 0s 8388607KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:10:9: error:
    • Couldn't match type ‘IO [Int]’ with ‘[Int]’
      Expected type: IO [Int]
        Actual type: IO (IO [Int])
    • In a stmt of a 'do' block: return (shuffle (i - 1) flipped)
      In the expression:
        do { n <- getStdRandom $ randomR (0, (length xs) - 1) :: IO Int;
             let part1 = take n xs
                 part2 = drop (n + 1) xs
                 ....;
             return (shuffle (i - 1) flipped) }
      In an equation for ‘shuffle’:
          shuffle i xs
            = do { n <- getStdRandom $ randomR (0, (length xs) - 1) :: IO Int;
                   let part1 = ...
                       ....;
                   return (shuffle (i - 1) flipped) }
stdout
Standard output is empty