
To help me learn Haskell, I decided on a simple (AH!) problem: given a list of images, display a random one as my desktop backdrop. After some time, change the image. Simple? What I actually want to do is a little more specific: Read a list of images (one per line) from a file. Given that a working day is about 8 hours, I want to see all the images during the day. So, the time between changes should be (nbr_of_images) / (8 * 60 * 60) seconds. Of course, if the file changes (I add or remove any number of images) this need to change and be recalculated. Clearly, I want some interaction with a pseudo-random number generator. Because this is a learning exercise, I want to have a pretty GUI for this. Three buttons: Exit (which quits the application), Reset (re-reads the file whether it changed or not) and Next (display the next image). Then I want a counter and a progress bar telling me when the next change will occur. 1- Get a list out of a file: I managed to do that using the following: parseImageFile :: FilePath -> IO [String] parseImageFile file = do inpStr <- readFile file return $ filter (/="") (breaks (=='\n') inpStr) Nice, simple and I understand what it is doing. 2- Get a random element from a list and remove it: Okay, this I understand less well. I looked at the solutions of problems 23 and 20 in http://www.haskell.org/haskellwiki/99_questions so there is a skeleton there. However, my list is IO [String].... Hum, monads. Any pointers as to how to do that? 3- Wait and do something later.... How, I have no idea how to do that! Help? 4- I guess that progress bars and updating text will be somewhere in the GUI (I chose wxHaskell)... Again, no idea where. 5- How do you call an external program in Haskell? Either xv or Esetroot will do the job of displaying the image. Is there a Haskell native way to do that? Once this is done and I have commented to the code, I will be happy to put it onto the wiki as a teaching aid. Thanks. -- yann@kierun.org -= H+ =- www.kierun.org PGP: 009D 7287 C4A7 FD4F 1680 06E4 F751 7006 9DE2 6318