fileName="/tmp/deleteme" string="something\n" write=writeFile fileName string append=appendFile fileName string read=readFile fileName -- write something and then read it back and check if they are the same test1= do write s <- read return (s==string) -- write something then append to it and then read it back and check if they are the same test2= do write append s <- read return (s==(string++string)) -- try to read from a file that does not exist. fileName2="doesnotexist" read2= do readFile fileName2 return () error= putStrLn "Error In Reading Caught by catchFail" test3= catchFail read2 error -- Apparently Haskel and Pakcs do not work as intended on this -- From M. Hanus, Mon Apr 18 13:24:12 PDT 2005 testLazy = do writeFile fileName "A" a <- readFile fileName writeFile fileName "B" b <- readFile fileName print (a == b) testFancy = do writeFile fileName ("012"++['a',chr(ord 'a' + 1),'c']) back <- readFile fileName print (back == "012abc") testAppend = do writeFile fileName prefix appendFile fileName suffix back <- readFile fileName print (back == prefix++suffix) where all = "The answer, my friend, is blowin' in the wind," middle = length all `div` 2 prefix = take middle all suffix = drop middle all coin = 0 ? 1 testCoin = putStrLn (show (12345 + coin))