lundi 23 mars 2015

Write list of random numbers to file. No Instance for (Show (IO a0))

I am trying to write to file a list of random Integers in a file. There seems to be a problem with writeFile here. When I use my function randomFile it says no instance for (Show (IO a0)). I see writeFile doesn't print anything to screen but IO(), so when I call the function randomFile 1 2 3 it says no Instance for Show (IO a0) but actually I just want to execute the function and not have to print anything but how can I avoid this problem. I might be making a lot of errors here. Any help.



import Control.Monad
import Control.Applicative
import System.Random

randNo mind maxd = randomRIO (mind,maxd)
randomFile mind maxd noe = do
let l=foldl (\ acc x -> (x $ maxd) : acc) ([]) (replicate (fromInteger(noe ^ noe)) ( mind `randNo`))
writeFile "RFile.txt" (show l)

Aucun commentaire:

Enregistrer un commentaire