No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{--
Shuffle a IO array
--}

import System.Random
import Control.Monad
import Data.Array.IO

aShuffle :: [a] -> IO [a]
aShuffle xs = do
                let
                  listLength = length xs
                  newArray :: Int -> [a] -> IO (IOArray Int a)
                  newArray n xs = newListArray (1, listLength) xs
                array <- newArray listLength xs
                forM [1..listLength] $ \i  -> do
                    j <- randomRIO (i, listLength)
                    valI <- readArray array i
                    valJ <- readArray array j
                    writeArray array j valI
                    return valJ

main = do
        xs <- aShuffle ["abcde"]
        print xs


{-- 

runhaskell shuffleList.hs
["abcde"]

--}
14:19: Error: Eta reduce
Found:
newArray n xs = newListArray (1, listLength) xs
Why not:
newArray n = newListArray (1, listLength)